I'm pulling my hair out trying to get my tests working to no avail. I am getting:
"Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL."
On every test in the suite. Then if I try to manually put it outside of Angulars home zone with ngZone.RunOutsideAngular or even the fakeAsync/tick combo in Jasmine I'm not getting any further.
Ideally I'd just like to set the intervals tick to something small in the BeforeEach which contains my test bed, but I'm not having any luck. I'm hoping maybe someone can help.
The offending code called in ngOnInit looks like this (interval in code is 30 seconds which is greater than jasmines 5 second timeout default):
protected initAutoSave(interval: number): void {
if (this.canAutoSave()) {
Observable.interval(interval)
.debounceTime(250)
.takeUntil(this.ngUnsubscribe)
.subscribe(() => {
this.DoTheDangThang();
});
}
}
This code works, but it's making Jasmine's Async "Proxy Zone" throw fits. In fact since it's in ngOnInit it seems to be crashing the TestBed and breaking every test in the suite.
My TestBed looks like something like this (minus the obfuscated names):
describe('MyContainerComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyContainerComponent],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{provide: MyService, useValue: myServiceStub},
{provide: MyStateService, useValue: myStateServiceStub},
{provide: MyContainerService, useValue: myContainerServiceStub},
{provide: OtherService, useValue: otherServiceStub},
{provide: YetAnotherService, useValue: yetAnotherServiceStub},
FormBuilder,
{
provide: ActivatedRoute, useClass: FakeActivatedRoute
}],
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader, useClass: FakeTranslateLoader
}
})]
})
.compileComponents().then(() => {
fixture = TestBed.createComponent(MyContainerComponent);
component = fixture.componentInstance;
//**************************************************************
//Attempt to change interval so jasmine won't time-out *
//but this line is not being honored (am I doing it too late?).*
component.autoSaveInterval = 100; *
//**************************************************************
component.translations = {
'Lang.App.Hello': 'Lang.App.Hello',
};
component.model = new ContainerModel(<Component>MyContainerComponent, MyApp.lang.title);
component.model.dataBag = {myItem: MyModelMock.mockMyModel()};
fixture.detectChanges();
translateService = fixture.debugElement.injector.get(TranslateService);
containerService = fixture.debugElement.injector.get(ContainerService);
stateService = fixture.debugElement.injector.get(ContainerStateService);
myThingService = fixture.debugElement.injector.get(MyThingService);
translateService.use('en');
}).catch((error) => {
console.log('error in MyContainerComponent');
console.log(error.message);
console.log(error.stack);
});
}));
Like I said above, I was hoping I could set the autoSaveInterval to something small in the test bed as not to cause jasmine to time-out, but I'm not having much luck and still getting the timeout error.
Tried fakeAsync\tick with no luck too, but would prefer just to set the interval lower in testbed sut if that can fix it. I suspect I'm just setting it in the wrong place however.
P.S. Setting jasmine.DEFAULT_TIMOUT_INTERVAL to 30 seconds isn't very realistic in this scenario due to number of tests in suite.
Any ideas?