I'm developing a Date Range picker component in Angular and having difficulty testing if input values are bad.
My ngOnInit() does a check for min/max date values.
When I attempt to write a test for this case
Jasmine returns:
Expected function to throw RangeError, but it threw TypeError: Cannot read property 'ngZone' of undefined.
Researching S.O. posts, led me to create a mock NgZone class and provide that in the TestBed, which simply leads to more problems such as "subscribe is undefined".
I thought this might be due to an EventEmitter, but I've tried removing that, and I receive the same errors.
First, how can I resolve the NgZone error? There are a few S.O. posts on this topic, but I seem to be coming up short.
Second, how can I properly test that my ngOnInit() behaves as expected if bad values are passed in?
Update
Even through I had isolated my input validation function, I still wasn't able to check if that function threw an error. Instead, I had to check detectChanges(), which is the function that invoked everything else:
expect(() => fixture.detectChanges()).toThrow();
ngOnInit()is behaving as expected. If I don't have to mock NgZone to accomplish that, I'll be just as happy.