I understand the root of the error, the component I'm testing requires a FormGroup
to be passed into it's @Input() form: FormGroup
. I just can't figure out how to pass one in when testing this component.
There error occurs in my before each function when I call fixture.detectChanges()
so the form must be passed in before that point
my current code get's the error group is not defined:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {
ReactiveFormsModule,
FormsModule,
Validators,
FormBuilder
} from '@angular/forms';
import { StaticComponent } from '../../firewall/static/static.component';
describe('StaticComponent', () => {
let component: StaticComponent;
let fixture: ComponentFixture<StaticComponent>;
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [
StaticComponent
],
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule
],
providers: [
NetworkService,
NetworkValidator,
HostNameValidator,
NotificationsService
]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(StaticComponent);
component = fixture.componentInstance;
component.ruleForm = FormBuilder.group({
chain: ['chain', Validators.required],
ip: [
'',
Validators.required,
this.networkValidator.validateNetwork('ip')
],
action: ['action', Validators.required]
});
fixture.detectChanges();
});
fit('should be created', () => {
expect(component).toBeTruthy();
});
});
How do I pass in a pre-fab form to my @Input of the component during the test? I cant seem to provide FormBuilder correctly