Angular zone onMicroTaskEmpty is undefined while testing

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Angular zone onMicroTaskEmpty is undefined while testing



I have the following testBed:


TestBed.configureTestingModule({
imports: [ReactiveFormsModule, MaterialModules, RouterTestingModule],
declarations: [SigninComponent, LoaderComponent],
providers: [
MatSnackBar, {
provide: Router, useClass: RouterTestingModule
}, {
provide: ActivatedRoute, useValue: {
snapshot: { params: Observable.of({ email: 'test@bizanalyst.in' }) }
}
}, {
provide: NgZone, useValue: mockNgZone
},
LoaderService,
FormBuilder,
StoreOperationService
]
}).compileComponents()



This test throws an error:


it('should have a defined component', () => {
expect(component).toBeNull(false)
})



The error is:


TypeError: Cannot read property 'subscribe' of undefined
at new ApplicationRef_ (webpack:///node_modules/@angular/core/@angular/core.es5.js:4684:0 <- config/spec-bundle.js:5351:37)
at _createClass (webpack:///node_modules/@angular/core/@angular/core.es5.js:9539:0 <- config/spec-bundle.js:10206:20)
at _createProviderInstance$1 (webpack:///node_modules/@angular/core/@angular/core.es5.js:9503:0 <- config/spec-bundle.js:10170:26)
at initNgModule (webpack:///node_modules/@angular/core/@angular/core.es5.js:9456:0 <- config/spec-bundle.js:10123:28)



The line corresponds to the error is inside the ApplicationRef function:


_this._zone.onMicrotaskEmpty.subscribe({ next: function () { _this._zone.run(function () { _this.tick(); }); } });




1 Answer
1



Just remove provide: NgZone, useValue: mockNgZone from your testing module dependencies. There is no need to use it in Jasmine. Just skip the declaration of NgZone in providers list.


provide: NgZone, useValue: mockNgZone






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

g53oh64mtxA uvZ6Ycu
zI9yFMo9,6 g2kEjywYe A2swUM2Z,V,ArXsOyJ

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template