You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During testing, I'm trying to keep the ReactiveFormsModule from being mocked using .keep(), but it very much seems to be mocked and then causing errors because it's a seemingly shallow mock.
An example of the bug
I have this component where I'm initializing a reactive form in the ngOnInit():
I'm trying to test it, where I actually want to keep the ReactiveFormsModule untouched, it should just work as in production:
describe('AppComponent',()=>{letsut: AppComponent;beforeEach(()=>MockBuilder(AppComponent).keep(ReactiveFormsModule));it('should initialize the form without errors',()=>{sut=MockRender(AppComponent).componentInstance;sut.ngOnInit();});});
But when running the test, it doesn't seem to keep that module as I intend:
TypeError: this.fb.control is not a function
If I console.log(this.fb); in my AppComponent, I see a mock:
I believe FormBuilder and its variants are not provided by FormsModule or ReactiveFormsModule. Hence this is not a bug in ng-mocks.
Hey, whadda know, I thought naaah when I read this, but I've removed the module from my AppComponent's imports array and serving the application actually still works. Well that's a surprise. Doesn't fix my problem, but still, interesting to know.
Hello there!
Description of the bug
During testing, I'm trying to keep the
ReactiveFormsModule
from being mocked using.keep()
, but it very much seems to be mocked and then causing errors because it's a seemingly shallow mock.An example of the bug
I have this component where I'm initializing a reactive form in the
ngOnInit()
:I'm trying to test it, where I actually want to keep the
ReactiveFormsModule
untouched, it should just work as in production:But when running the test, it doesn't seem to keep that module as I intend:
If I
console.log(this.fb);
in myAppComponent
, I see a mock:NonNullableFormBuilder __ngMocks: true [[Prototype]]: Object
Link: https://github.com/JPtenBerge/ng-mocks-reactive-forms-bug
Expected vs actual behavior
Expected: all form functions (
fb.group()
,fb.control()
) to work as when serving the app.Actual: it's a mock without any of the functions.
The text was updated successfully, but these errors were encountered: