feat(test): Implement fakeAsync using the FakeAsyncTestZoneSpec from zone.js.

Update the version of zone.js to @0.6.12 that contains the new FakeAsyncTestZoneSpec.

The new fakeAsync zone handles errors better and clearPendingTimers() is no longer required to be called after handling an error and is deprecated.

The fakeAsync test zone will now throw an error if an XHR is attemtped within the test since that cannot be controlled synchronously in the test(Need to be mocked out with a service implementation that doesn't involve XHRs).

This commit also allows fakeAsync to wrap inject to make it consistent with async test zone.

BREAKING CHANGE:

inject can no longer wrap fakeAsync while fakeAsync can wrap inject. So the order in existing tests with inject and fakeAsync has to be switched as follows:

Before:
```
inject([...], fakeAsync((...) => {...}))
```

After:
```
fakeAsync(inject([...], (...) => {...}))
```

Closes #8142
This commit is contained in:
Vikram Subramanian
2016-04-18 16:04:35 -07:00
committed by vikerman
parent cc86fee1d1
commit bab81a9831
15 changed files with 448 additions and 520 deletions
@@ -34,7 +34,7 @@ export function main() {
});
it('should work with inject()',
inject([Parser], fakeAsync((parser) => { expect(parser).toBeAnInstanceOf(Parser); })));
fakeAsync(inject([Parser], (parser) => { expect(parser).toBeAnInstanceOf(Parser); })));
it('should throw on nested calls', () => {
expect(() => { fakeAsync(() => { fakeAsync(() => null)(); })(); })
@@ -259,6 +259,5 @@ export function main() {
.toThrowError('The code should be running in the fakeAsync zone to call this function');
});
});
});
}
@@ -106,13 +106,12 @@ export function main() {
it('provides a real XHR instance',
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
it('should allow the use of fakeAsync',
inject([FancyService], fakeAsync((service) => {
var value;
service.getAsyncValue().then(function(val) { value = val; });
tick();
expect(value).toEqual('async value');
})));
it('should allow the use of fakeAsync', fakeAsync(inject([FancyService], (service) => {
var value;
service.getAsyncValue().then(function(val) { value = val; });
tick();
expect(value).toEqual('async value');
})));
});
});
@@ -9,6 +9,8 @@ import {
beforeEach,
inject,
async,
fakeAsync,
tick,
withProviders,
beforeEachProviders,
TestComponentBuilder
@@ -142,6 +144,13 @@ export function main() {
service.getTimeoutValue().then((value) => { expect(value).toEqual('timeout value'); });
})));
it('should allow the use of fakeAsync', fakeAsync(inject([FancyService], (service) => {
var value;
service.getAsyncValue().then(function(val) { value = val; });
tick();
expect(value).toEqual('async value');
})));
describe('using beforeEach', () => {
beforeEach(inject([FancyService],
(service) => { service.value = 'value modified in beforeEach'; }));