How can I from within an angular2 runtime detect that I am running in e2e test mode? I have a session refresh interval that I do not want to set up when in test mode to avoid synchronization problems with protractor.
An obvious answer would be to look for a URL parameter. Is there a less dirty solution?
EDIT (clarification before bounty):
Protractor is wired to angular (1 or 2) in such way that it will wait for all outstanding work to finish before evaluating anything. That means that all outstanding angular promises
or any active angular timer
will hang protractor tests (and eventually cause them to fail). The most commonly proposed solution is to set browser.ignoreSynchronization = true
but that would force me to either nest all e2e tests in callback-chains or use a bunch of sleeps. Probably both. So it seems I am stuck between a rock and a hard place either having a real uphill experience writing e2e tests or setting a condition around a particular line of application code to not run when in "test mode" (eww, ugly). I choose to have easier e2e test as I expect to write them in the hundreds and so far we are only talking about one interval that isn't critical during testing (30 minute interval for session refresh).
You can start your timeouts/intervals outside of angulars zone through
ngZone.runOutsideAngular(() => {
// start your timeout/interval here
});
This will avoid protractor waiting for the timeout/interval to finish. For more information see: https://github.com/angular/protractor/issues/3349
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With