Revert "feat(core): add support for using async/await with Jasmine" (#25096)
This reverts commit f6829aba55e07609e312b4f67dbc9dbbf36e4e46. PR Close #25096
This commit is contained in:
parent
968f153491
commit
e1c6fd5453
@ -6,8 +6,6 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {jasmineAwait} from '@angular/core/testing';
|
|
||||||
|
|
||||||
import {Component} from '../../src/core';
|
import {Component} from '../../src/core';
|
||||||
import {clearResolutionOfComponentResourcesQueue, resolveComponentResources} from '../../src/metadata/resource_loading';
|
import {clearResolutionOfComponentResourcesQueue, resolveComponentResources} from '../../src/metadata/resource_loading';
|
||||||
import {ComponentType} from '../../src/render3/interfaces/definition';
|
import {ComponentType} from '../../src/render3/interfaces/definition';
|
||||||
@ -60,7 +58,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
}
|
}
|
||||||
beforeEach(() => resourceFetchCount = 0);
|
beforeEach(() => resourceFetchCount = 0);
|
||||||
|
|
||||||
it('should resolve template', jasmineAwait(async() => {
|
it('should resolve template', async() => {
|
||||||
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
||||||
const metadata: Component = {templateUrl: 'test://content'};
|
const metadata: Component = {templateUrl: 'test://content'};
|
||||||
compileComponent(MyComponent, metadata);
|
compileComponent(MyComponent, metadata);
|
||||||
@ -69,9 +67,9 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
expect(metadata.templateUrl).toBe(undefined);
|
expect(metadata.templateUrl).toBe(undefined);
|
||||||
expect(metadata.template).toBe('content');
|
expect(metadata.template).toBe('content');
|
||||||
expect(resourceFetchCount).toBe(1);
|
expect(resourceFetchCount).toBe(1);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should resolve styleUrls', jasmineAwait(async() => {
|
it('should resolve styleUrls', async() => {
|
||||||
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
||||||
const metadata: Component = {template: '', styleUrls: ['test://style1', 'test://style2']};
|
const metadata: Component = {template: '', styleUrls: ['test://style1', 'test://style2']};
|
||||||
compileComponent(MyComponent, metadata);
|
compileComponent(MyComponent, metadata);
|
||||||
@ -80,9 +78,9 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
expect(metadata.styleUrls).toBe(undefined);
|
expect(metadata.styleUrls).toBe(undefined);
|
||||||
expect(metadata.styles).toEqual(['style1', 'style2']);
|
expect(metadata.styles).toEqual(['style1', 'style2']);
|
||||||
expect(resourceFetchCount).toBe(2);
|
expect(resourceFetchCount).toBe(2);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should cache multiple resolution to same URL', jasmineAwait(async() => {
|
it('should cache multiple resolution to same URL', async() => {
|
||||||
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
||||||
const metadata: Component = {template: '', styleUrls: ['test://style1', 'test://style1']};
|
const metadata: Component = {template: '', styleUrls: ['test://style1', 'test://style1']};
|
||||||
compileComponent(MyComponent, metadata);
|
compileComponent(MyComponent, metadata);
|
||||||
@ -91,9 +89,9 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
expect(metadata.styleUrls).toBe(undefined);
|
expect(metadata.styleUrls).toBe(undefined);
|
||||||
expect(metadata.styles).toEqual(['style1', 'style1']);
|
expect(metadata.styles).toEqual(['style1', 'style1']);
|
||||||
expect(resourceFetchCount).toBe(1);
|
expect(resourceFetchCount).toBe(1);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should keep order even if the resolution is out of order', jasmineAwait(async() => {
|
it('should keep order even if the resolution is out of order', async() => {
|
||||||
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
||||||
const metadata: Component = {
|
const metadata: Component = {
|
||||||
template: '',
|
template: '',
|
||||||
@ -112,7 +110,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
await resolved;
|
await resolved;
|
||||||
expect(metadata.styleUrls).toBe(undefined);
|
expect(metadata.styleUrls).toBe(undefined);
|
||||||
expect(metadata.styles).toEqual(['existing', 'first', 'second']);
|
expect(metadata.styles).toEqual(['existing', 'first', 'second']);
|
||||||
}));
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -123,7 +121,7 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
} as any as Response);
|
} as any as Response);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should work with fetch', jasmineAwait(async() => {
|
it('should work with fetch', async() => {
|
||||||
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
const MyComponent: ComponentType<any> = (class MyComponent{}) as any;
|
||||||
const metadata: Component = {templateUrl: 'test://content'};
|
const metadata: Component = {templateUrl: 'test://content'};
|
||||||
compileComponent(MyComponent, metadata);
|
compileComponent(MyComponent, metadata);
|
||||||
@ -131,6 +129,6 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
|
|||||||
expect(MyComponent.ngComponentDef).toBeDefined();
|
expect(MyComponent.ngComponentDef).toBeDefined();
|
||||||
expect(metadata.templateUrl).toBe(undefined);
|
expect(metadata.templateUrl).toBe(undefined);
|
||||||
expect(metadata.template).toBe('response for test://content');
|
expect(metadata.template).toBe('response for test://content');
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
/**
|
|
||||||
* @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);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* @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
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts an `async` function, with `await`, into a function which is compatible with Jasmine test
|
|
||||||
* framework.
|
|
||||||
*
|
|
||||||
* For asynchronous function blocks, Jasmine expects `it` (and friends) to take a function which
|
|
||||||
* takes a `done` callback. (Jasmine does not understand functions which return `Promise`.) The
|
|
||||||
* `jasmineAwait()` wrapper converts the test function returning `Promise` into a function which
|
|
||||||
* Jasmine understands.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* ```
|
|
||||||
* it('...', jasmineAwait(async() => {
|
|
||||||
* doSomething();
|
|
||||||
* await asyncFn();
|
|
||||||
* doSomethingAfter();
|
|
||||||
* }));
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export function jasmineAwait(fn: () => Promise<any>):
|
|
||||||
(done: {(): void; fail: (message?: Error | string) => void;}) => void {
|
|
||||||
return function(done: {(): void; fail: (message?: Error | string) => void;}) {
|
|
||||||
fn().then(done, done.fail);
|
|
||||||
};
|
|
||||||
}
|
|
@ -13,7 +13,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './async';
|
export * from './async';
|
||||||
export * from './jasmine_await';
|
|
||||||
export * from './component_fixture';
|
export * from './component_fixture';
|
||||||
export * from './fake_async';
|
export * from './fake_async';
|
||||||
export * from './test_bed';
|
export * from './test_bed';
|
||||||
|
5
tools/public_api_guard/core/testing.d.ts
vendored
5
tools/public_api_guard/core/testing.d.ts
vendored
@ -53,11 +53,6 @@ export declare class InjectSetupWrapper {
|
|||||||
inject(tokens: any[], fn: Function): () => any;
|
inject(tokens: any[], fn: Function): () => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare function jasmineAwait(fn: () => Promise<any>): (done: {
|
|
||||||
(): void;
|
|
||||||
fail: (message?: Error | string) => void;
|
|
||||||
}) => void;
|
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare type MetadataOverride<T> = {
|
export declare type MetadataOverride<T> = {
|
||||||
add?: Partial<T>;
|
add?: Partial<T>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user