Created
May 3, 2018 09:32
-
-
Save jonrimmer/6d7fcf4c1bcbaed126e57a8e457016aa to your computer and use it in GitHub Desktop.
Clearing all pending tasks from the fake async zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { fakeAsync, tick } from '@angular/core/testing'; | |
import { discardFakeAsyncTimers ) from './helpers'; | |
const myComponent = {}; | |
describe('My Component', () => { | |
before(fakeAsync(() => { | |
myComponent.getAsyncData(); | |
// Run async stuff. | |
tick(); | |
// Uh oh, some code we don't control keeps adding async tasks! | |
discardFakeAsyncTimers(); | |
// Gone now. | |
})); | |
it('should work', () => { | |
expect(myComponent.asyncResult).toBe('correct'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'zone.js'; | |
export function discardFakeAsyncTimers() { | |
const fakeZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec'); | |
fakeZoneSpec.pendingPeriodicTimers.length = 0; | |
fakeZoneSpec.pendingTimers.length = 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment