2016-08-02 10:38:14 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2016-08-02 10:54:14 -04:00
|
|
|
import {APP_INITIALIZER, ApplicationInitStatus} from '../src/application_init';
|
2016-09-27 20:12:25 -04:00
|
|
|
import {TestBed, async, inject} from '../testing';
|
2016-08-02 10:38:14 -04:00
|
|
|
|
|
|
|
export function main() {
|
2016-08-02 10:54:14 -04:00
|
|
|
describe('ApplicationInitStatus', () => {
|
2016-08-02 10:38:14 -04:00
|
|
|
describe('no initializers', () => {
|
|
|
|
|
|
|
|
it('should return true for `done`',
|
2016-08-19 15:10:53 -04:00
|
|
|
async(inject([ApplicationInitStatus], (status: ApplicationInitStatus) => {
|
2016-08-02 10:54:14 -04:00
|
|
|
expect(status.done).toBe(true);
|
2016-08-19 15:10:53 -04:00
|
|
|
})));
|
2016-08-02 10:38:14 -04:00
|
|
|
|
|
|
|
it('should return a promise that resolves immediately for `donePromise`',
|
2016-08-02 10:54:14 -04:00
|
|
|
async(inject([ApplicationInitStatus], (status: ApplicationInitStatus) => {
|
2016-08-02 10:38:14 -04:00
|
|
|
status.donePromise.then(() => { expect(status.done).toBe(true); });
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with async initializers', () => {
|
2016-08-02 18:53:34 -04:00
|
|
|
let resolve: (result: any) => void;
|
|
|
|
let promise: Promise<any>;
|
2016-08-02 10:38:14 -04:00
|
|
|
beforeEach(() => {
|
2016-08-02 18:53:34 -04:00
|
|
|
promise = new Promise((res) => { resolve = res; });
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
{providers: [{provide: APP_INITIALIZER, multi: true, useValue: () => promise}]});
|
2016-08-02 10:38:14 -04:00
|
|
|
});
|
|
|
|
|
2016-12-29 12:41:21 -05:00
|
|
|
it('should update the status once all async initializers are done',
|
2016-08-02 10:54:14 -04:00
|
|
|
async(inject([ApplicationInitStatus], (status: ApplicationInitStatus) => {
|
2016-08-02 10:38:14 -04:00
|
|
|
let completerResolver = false;
|
|
|
|
setTimeout(() => {
|
|
|
|
completerResolver = true;
|
2016-08-02 18:53:34 -04:00
|
|
|
resolve(null);
|
2016-08-02 10:38:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(status.done).toBe(false);
|
|
|
|
status.donePromise.then(() => {
|
|
|
|
expect(status.done).toBe(true);
|
|
|
|
expect(completerResolver).toBe(true);
|
|
|
|
});
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
});
|
2016-08-02 18:53:34 -04:00
|
|
|
}
|