Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
feat(jasmine): Switch jasmine patch to use microtask and preserve zone.
Browse files Browse the repository at this point in the history
Previous implementation used setTimeout which make tests too slow.
It also did not propagate zones across a reset.
  • Loading branch information
mhevery committed Aug 15, 2016
1 parent fd1dfcc commit 5f519de
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/jasmine/jasmine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
if (!Zone) {
throw new Error('zone.js does not seem to be installed');
}

const SET_TIMEOUT = '__zone_symbol__setTimeout';
const _global = typeof window == 'undefined' ? global : window;


// When you have in async test (test with `done` argument) jasmine will
// execute the next test synchronously in the done handler. This makes sense
// for most tests, but now with zones. With zones running next test
Expand All @@ -17,10 +12,14 @@ const _global = typeof window == 'undefined' ? global : window;
// it. We override the `clearStack` method which forces jasmine to always
// drain the stack before next test gets executed.
(<any>jasmine).QueueRunner = (function (SuperQueueRunner) {
const originalZone = Zone.current;
// Subclass the `QueueRunner` and override the `clearStack` method.

function alwaysClearStack(fn) {
_global[SET_TIMEOUT](fn, 0);
const zone: Zone = Zone.current.getZoneWith('JasmineClearStackZone')
|| Zone.current.getZoneWith('ProxyZoneSpec')
|| originalZone;
zone.scheduleMicroTask('jasmineCleanStack', fn);
}

function QueueRunner(options) {
Expand Down

0 comments on commit 5f519de

Please sign in to comment.