feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function to wrap tests. This will run the test inside a zone which does not complete the test until all asynchronous tasks have been completed. `async` may be used with the `inject` function, or separately. BREAKING CHANGE: `injectAsync` is now deprecated. Instead, use the `async` function to wrap any asynchronous tests. Before: ``` it('should wait for returned promises', injectAsync([FancyService], (service) => { return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); }); })); it('should wait for returned promises', injectAsync([], () => { return somePromise.then(() => { expect(true).toEqual(true); }); })); ``` After: ``` it('should wait for returned promises', async(inject([FancyService], (service) => { service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); }); }))); // Note that if there is no injection, we no longer need `inject` OR `injectAsync`. it('should wait for returned promises', async(() => { somePromise.then() => { expect(true).toEqual(true); }); })); ``` Closes #7735
This commit is contained in:

committed by
Robert Messerle

parent
ecb9bb96f0
commit
8490921fb3
@ -76,7 +76,7 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||
'angular2/test/animate/**',
|
||||
'angular2/test/core/zone/**',
|
||||
'angular2/test/testing/fake_async_spec.ts',
|
||||
'angular2/test/testing/testing_public_spec.ts',
|
||||
'angular2/test/testing/testing_public_browser_spec.ts',
|
||||
'angular2/test/platform/xhr_impl_spec.ts',
|
||||
'angular2/test/platform/browser/**/*.ts',
|
||||
'angular2/test/common/forms/**',
|
||||
|
@ -3,9 +3,10 @@
|
||||
var glob = require('glob');
|
||||
var JasmineRunner = require('jasmine');
|
||||
var path = require('path');
|
||||
// require('es6-shim/es6-shim.js');
|
||||
require('zone.js/dist/zone-node.js');
|
||||
require('zone.js/dist/long-stack-trace-zone.js');
|
||||
require('es6-shim/es6-shim.js');
|
||||
require('zone.js/dist/async-test.js');
|
||||
require('reflect-metadata/Reflect');
|
||||
|
||||
var jrunner = new JasmineRunner();
|
||||
@ -36,4 +37,5 @@ jrunner.projectBaseDir = path.resolve(__dirname, '../../');
|
||||
jrunner.specDir = '';
|
||||
jrunner.addSpecFiles(specFiles);
|
||||
require('./test-cjs-main.js');
|
||||
require('zone.js/dist/jasmine-patch.js');
|
||||
jrunner.execute();
|
||||
|
Reference in New Issue
Block a user