NgMocks ParentFormGroup as an input

79 views Asked by At

I have a component that renders out a form array & registers itself as one of the parents form's form controls.

This is all working correctly, but i cant get the unit tests to accept a parentFormGroup as an input that i am trying to pass in.

I am using ngMocks to render my component and trying to pass in the formGroup as the second argument.

const fixture = MockRender(Component, {parentFormGroup: new FormGroup({}))
expect(fixture.point.componentInstance.toBeDefined())

But i just keep getting an error as my ngOnInit method is trying to access that parent form group to register itself against.

public ngOnInit() {
    this.parentFormGroup.addControl('test', this.form)
}

But this just returns cannot read properties of undefined reading 'setParent'.

Also worth noting this is using @ngneats/reactive-forms package

0

There are 0 answers