Created
February 8, 2018 16:26
-
-
Save CHBaker/a1f827db25aa1a7f41d37d15c71d79cf to your computer and use it in GitHub Desktop.
Working test with FormBuilder passing in dynamically a ReactiveForm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
import { ReactiveFormsModule, FormBuilder } from '@angular/forms'; | |
import { CommonModule } from '@angular/common'; | |
import { AppModule } from './app.module'; | |
import { ChildComponent } from './child.component'; | |
describe('StaticComponent', () => { | |
let component: StaticComponent; | |
let fixture: ComponentFixture<ChildComponent>; | |
// create new instance of FormBuilder | |
const formBuilder: FormBuilder = new FormBuilder(); | |
beforeEach( | |
async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [ | |
ChildComponent | |
], | |
imports: [ | |
CommonModule, | |
ReactiveFormsModule, | |
AppModule | |
], | |
providers: [ | |
// reference the new instance of formBuilder from above | |
{ provide: FormBuilder, useValue: formBuilder } | |
] | |
}).compileComponents(); | |
}) | |
); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(ChildComponent); | |
component = fixture.componentInstance; | |
// pass in the form dynamically | |
component.nameForm = formBuilder.group({ | |
firstName: null, | |
lastName: null | |
}); | |
fixture.detectChanges(); | |
}); | |
it('should be created', () => { | |
expect(component).toBeTruthy(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment