2016-06-23 16:47:54 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 16:47:54 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2016-06-23 16:47:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-08-17 16:24:44 +00:00
|
|
|
import {ResourceLoader} from '@angular/compiler';
|
2025-09-09 19:24:22 +00:00
|
|
|
import {
|
|
|
|
|
Compiler,
|
|
|
|
|
Component,
|
|
|
|
|
getPlatform,
|
|
|
|
|
NgModule,
|
|
|
|
|
provideZonelessChangeDetection,
|
|
|
|
|
} from '@angular/core';
|
2020-07-31 19:43:18 +00:00
|
|
|
import {fakeAsync, inject, TestBed, tick, waitForAsync} from '@angular/core/testing';
|
2019-01-05 03:10:14 +00:00
|
|
|
import {ResourceLoaderImpl} from '../src/resource_loader/resource_loader_impl';
|
2025-04-30 12:40:02 +00:00
|
|
|
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '../testing';
|
|
|
|
|
import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing';
|
|
|
|
|
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
2025-05-19 10:54:54 +00:00
|
|
|
import {isBrowser} from '@angular/private/testing';
|
2025-09-09 19:24:22 +00:00
|
|
|
@NgModule({
|
|
|
|
|
providers: [provideZonelessChangeDetection()],
|
|
|
|
|
})
|
|
|
|
|
export class TestModule {}
|
2016-07-11 23:04:32 +00:00
|
|
|
|
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
2016-03-23 17:59:38 +00:00
|
|
|
// Components for the tests.
|
|
|
|
|
class FancyService {
|
|
|
|
|
value: string = 'real value';
|
2020-04-13 23:40:21 +00:00
|
|
|
getAsyncValue() {
|
|
|
|
|
return Promise.resolve('async value');
|
|
|
|
|
}
|
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
2016-03-23 17:59:38 +00:00
|
|
|
getTimeoutValue() {
|
2020-04-13 23:40:21 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
resolve('timeout value');
|
|
|
|
|
}, 10);
|
|
|
|
|
});
|
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
2016-03-23 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 16:44:35 +00:00
|
|
|
// Tests for angular/testing bundle specific to the browser environment.
|
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
2016-03-23 17:59:38 +00:00
|
|
|
// For general tests, see test/testing/testing_public_spec.ts.
|
2018-10-19 23:43:31 +00:00
|
|
|
if (isBrowser) {
|
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
2016-03-23 17:59:38 +00:00
|
|
|
describe('test APIs for the browser', () => {
|
|
|
|
|
describe('using the async helper', () => {
|
2016-11-12 13:08:58 +00:00
|
|
|
let actuallyDone: boolean;
|
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
2016-03-23 17:59:38 +00:00
|
|
|
|
2020-04-13 23:40:21 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
|
actuallyDone = false;
|
|
|
|
|
});
|
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
2016-03-23 17:59:38 +00:00
|
|
|
|
2020-04-13 23:40:21 +00:00
|
|
|
afterEach(() => {
|
|
|
|
|
expect(actuallyDone).toEqual(true);
|
|
|
|
|
});
|
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
2016-03-23 17:59:38 +00:00
|
|
|
|
2020-07-31 19:43:18 +00:00
|
|
|
it('should run async tests with ResourceLoaders', waitForAsync(() => {
|
2016-11-12 13:08:58 +00:00
|
|
|
const resourceLoader = new ResourceLoaderImpl();
|
2025-06-26 12:50:03 +00:00
|
|
|
resourceLoader.get('/packages/platform-browser/test/static_assets/test.html').then(() => {
|
|
|
|
|
actuallyDone = true;
|
|
|
|
|
});
|
2016-08-17 16:24:44 +00:00
|
|
|
}), 10000); // Long timeout here because this test makes an actual ResourceLoader.
|
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
2016-03-23 17:59:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('using the test injector with the inject helper', () => {
|
|
|
|
|
describe('setting up Providers', () => {
|
2016-08-10 18:51:40 +00:00
|
|
|
beforeEach(() => {
|
2025-04-30 12:40:02 +00:00
|
|
|
getPlatform()?.destroy();
|
|
|
|
|
// We need to reset the test environment because
|
|
|
|
|
// browser_tests.init.ts doesn't use platformBrowserDynamicTesting
|
|
|
|
|
TestBed.resetTestEnvironment();
|
|
|
|
|
TestBed.initTestEnvironment(
|
2025-09-09 19:24:22 +00:00
|
|
|
[BrowserDynamicTestingModule, TestModule],
|
2025-04-30 12:40:02 +00:00
|
|
|
platformBrowserDynamicTesting(),
|
|
|
|
|
);
|
|
|
|
|
|
2016-08-10 18:51:40 +00:00
|
|
|
TestBed.configureTestingModule({
|
|
|
|
|
providers: [{provide: FancyService, useValue: new FancyService()}],
|
|
|
|
|
});
|
|
|
|
|
});
|
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
2016-03-23 17:59:38 +00:00
|
|
|
|
2019-01-17 01:13:23 +00:00
|
|
|
it('provides a real ResourceLoader instance', inject(
|
|
|
|
|
[ResourceLoader],
|
|
|
|
|
(resourceLoader: ResourceLoader) => {
|
|
|
|
|
expect(resourceLoader instanceof ResourceLoaderImpl).toBeTruthy();
|
|
|
|
|
},
|
|
|
|
|
));
|
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
2016-03-23 17:59:38 +00:00
|
|
|
|
2016-06-08 23:38:52 +00:00
|
|
|
it('should allow the use of fakeAsync', fakeAsync(
|
2023-03-12 22:44:50 +00:00
|
|
|
inject([FancyService], (service: FancyService) => {
|
|
|
|
|
let value: string | undefined;
|
|
|
|
|
service.getAsyncValue().then(function (val: string) {
|
2020-04-13 23:40:21 +00:00
|
|
|
value = val;
|
|
|
|
|
});
|
2016-04-18 23:04:35 +00:00
|
|
|
tick();
|
|
|
|
|
expect(value).toEqual('async value');
|
|
|
|
|
}),
|
|
|
|
|
));
|
2025-04-30 12:40:02 +00:00
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
getPlatform()?.destroy();
|
|
|
|
|
|
|
|
|
|
// We're reset the test environment to their default values, cf browser_tests.init.ts
|
|
|
|
|
TestBed.resetTestEnvironment();
|
|
|
|
|
TestBed.initTestEnvironment(
|
2025-09-09 19:24:22 +00:00
|
|
|
[BrowserTestingModule, NoopAnimationsModule, TestModule],
|
2025-04-30 12:40:02 +00:00
|
|
|
platformBrowserTesting(),
|
|
|
|
|
);
|
|
|
|
|
});
|
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
2016-03-23 17:59:38 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-01 19:02:48 +00:00
|
|
|
describe('Compiler', () => {
|
2019-01-12 05:19:55 +00:00
|
|
|
it('should return NgModule id when asked', () => {
|
|
|
|
|
@NgModule({
|
|
|
|
|
id: 'test-module',
|
|
|
|
|
})
|
|
|
|
|
class TestModule {}
|
|
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
|
imports: [TestModule],
|
|
|
|
|
});
|
2019-08-28 23:22:36 +00:00
|
|
|
const compiler = TestBed.inject(Compiler);
|
2019-01-12 05:19:55 +00:00
|
|
|
expect(compiler.getModuleId(TestModule)).toBe('test-module');
|
|
|
|
|
});
|
2018-06-01 19:02:48 +00:00
|
|
|
});
|
|
|
|
|
|
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
2016-03-23 17:59:38 +00:00
|
|
|
describe('errors', () => {
|
2021-05-07 12:17:46 +00:00
|
|
|
describe('should fail when an ResourceLoader fails', () => {
|
2021-11-09 19:02:39 +00:00
|
|
|
// TODO(alxhub): figure out why this is failing on saucelabs
|
|
|
|
|
xit('should fail with an error from a promise', async () => {
|
2024-10-11 10:32:52 +00:00
|
|
|
@Component({
|
|
|
|
|
selector: 'bad-template-comp',
|
|
|
|
|
templateUrl: 'non-existent.html',
|
|
|
|
|
standalone: false,
|
|
|
|
|
})
|
2021-11-09 19:02:39 +00:00
|
|
|
class BadTemplateUrl {}
|
|
|
|
|
|
2021-05-07 12:17:46 +00:00
|
|
|
TestBed.configureTestingModule({declarations: [BadTemplateUrl]});
|
|
|
|
|
await expectAsync(TestBed.compileComponents()).toBeRejectedWith(
|
|
|
|
|
'Failed to load non-existent.html',
|
|
|
|
|
);
|
|
|
|
|
}, 10000);
|
|
|
|
|
});
|
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
2016-03-23 17:59:38 +00:00
|
|
|
});
|
|
|
|
|
|
2016-08-19 22:46:40 +00:00
|
|
|
describe('TestBed createComponent', function () {
|
2021-11-09 19:02:39 +00:00
|
|
|
// TODO(alxhub): disable while we figure out how this should work
|
|
|
|
|
xit('should allow an external templateUrl', waitForAsync(() => {
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'external-template-comp',
|
|
|
|
|
templateUrl: '/base/angular/packages/platform-browser/test/static_assets/test.html',
|
2024-10-11 10:32:52 +00:00
|
|
|
standalone: false,
|
2021-11-09 19:02:39 +00:00
|
|
|
})
|
|
|
|
|
class ExternalTemplateComp {}
|
|
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({declarations: [ExternalTemplateComp]});
|
|
|
|
|
TestBed.compileComponents().then(() => {
|
|
|
|
|
const componentFixture = TestBed.createComponent(ExternalTemplateComp);
|
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
|
expect(componentFixture.nativeElement.textContent).toEqual('from external template');
|
|
|
|
|
});
|
|
|
|
|
}), 10000); // Long timeout here because this test makes an actual ResourceLoader
|
|
|
|
|
// request, and is slow on Edge.
|
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
2016-03-23 17:59:38 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|