I just started to write e2e tests for my app and am running into timeout problems with Protractor and ngrx/effects.
I have the following effect dispatching an action every couple of minutes:
@Effect() setSessionTimer$ = this.actions$
.ofType(Auth.ActionTypes.SET_SECONDS_LEFT)
.map(toPayload)
.switchMap(secondsLeft => Observable.concat(
Observable.timer((secondsLeft - 60) * 1000).map(_ => new Auth.SessionExpiringAction(60)),
Observable.timer(60 * 1000).map(_ => new Auth.SessionExpiredAction())
));
Trying to run a Protractor test causes the test to timeout with the following error, since Angular is not stable.
Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular While waiting for element with locator - Locator: By(css selector, .toolbar-title)
According to this issue (https://github.com/angular/protractor/issues/3349) I need to use NgZone to run an interval Observable outside of Angular. I have tried different combinations of this.ngZone.runOutsideAngular()
but nothing worked and the tests keep on timing out.
For example this does not work:
@Effect() setSessionTimer$ = this.actions$
.ofType(Auth.ActionTypes.SET_SECONDS_LEFT)
.map(toPayload)
.switchMap(secondsLeft => this.ngZone.runOutsideAngular(() => Observable.concat(
Observable.timer((secondsLeft - 60) * 1000).map(_ => new Auth.SessionExpiringAction(60)),
Observable.timer(60 * 1000).map(_ => new Auth.SessionExpiredAction())
)));
I have no idea how to run the effect outside Angular. Has anybody successfully e2e tested their ngrx app?