feat(core): add support for using async/await with Jasmine (#24637)
Example: ``` it('...', await(async() => { doSomething(); await asyncFn(); doSomethingAfter(); })); ``` PR Close #24637
This commit is contained in:

committed by
Miško Hevery

parent
676ec411b9
commit
71100e6d72
31
packages/core/test/testability/jasmine_await_spec.ts
Normal file
31
packages/core/test/testability/jasmine_await_spec.ts
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {jasmineAwait} from '../../testing';
|
||||
|
||||
|
||||
describe('await', () => {
|
||||
let pass: boolean;
|
||||
beforeEach(() => pass = false);
|
||||
afterEach(() => expect(pass).toBe(true));
|
||||
|
||||
it('should convert passes', jasmineAwait(async() => { pass = await Promise.resolve(true); }));
|
||||
|
||||
it('should convert failures', (done) => {
|
||||
const error = new Error();
|
||||
const fakeDone: DoneFn = function() { fail('passed, but should have failed'); } as any;
|
||||
fakeDone.fail = function(value: any) {
|
||||
expect(value).toBe(error);
|
||||
done();
|
||||
};
|
||||
jasmineAwait(async() => {
|
||||
pass = await Promise.resolve(true);
|
||||
throw error;
|
||||
})(fakeDone);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user