mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
test(module-loader): add test for two modules loaded at once
This commit is contained in:
@ -10,14 +10,14 @@ describe('module-loader', () => {
|
|||||||
it('should call ngModuleLoader and receive a promise back', (done: Function) => {
|
it('should call ngModuleLoader and receive a promise back', (done: Function) => {
|
||||||
spyOn(ngModuleLoader, 'load').and.returnValue(Promise.resolve());
|
spyOn(ngModuleLoader, 'load').and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
const knownPathPrefix = '../some/known/path';
|
let pathPrefix = '../some/known/path';
|
||||||
const knownExportSuffix = 'SomeModule';
|
let exportSuffix = 'SomeModule';
|
||||||
const loadChildrenValue = knownPathPrefix + '#' + knownExportSuffix;
|
let loadChildren = pathPrefix + '#' + exportSuffix;
|
||||||
|
|
||||||
const promise = moduleLoader.load(loadChildrenValue);
|
let promise = moduleLoader.load(loadChildren);
|
||||||
|
|
||||||
promise.then((response) => {
|
promise.then((response) => {
|
||||||
expect(ngModuleLoader.load).toHaveBeenCalledWith(knownPathPrefix, knownExportSuffix);
|
expect(ngModuleLoader.load).toHaveBeenCalledWith(pathPrefix, exportSuffix);
|
||||||
}).catch((err: Error) => {
|
}).catch((err: Error) => {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
@ -33,21 +33,66 @@ describe('module-loader', () => {
|
|||||||
|
|
||||||
spyOn(ngModuleLoader, 'load').and.returnValue(promise);
|
spyOn(ngModuleLoader, 'load').and.returnValue(promise);
|
||||||
|
|
||||||
const knownPathPrefix = '../some/known/path';
|
let pathPrefix = '../some/known/path';
|
||||||
const knownExportSuffix = 'SomeModule';
|
let exportSuffix = 'SomeModule';
|
||||||
const loadChildrenValue = knownPathPrefix + '#' + knownExportSuffix;
|
let loadChildren = pathPrefix + '#' + exportSuffix;
|
||||||
|
|
||||||
promise = moduleLoader.load(loadChildrenValue);
|
promise = moduleLoader.load(loadChildren);
|
||||||
|
|
||||||
// the promise is not resolved
|
// the promise is not resolved
|
||||||
let secondPromise = moduleLoader.load(loadChildrenValue);
|
let secondPromise = moduleLoader.load(loadChildren);
|
||||||
|
|
||||||
// we would expect the same promise to be returned both times
|
// The promise returned should be the cached promise
|
||||||
expect(promise).toEqual(secondPromise);
|
expect(promise).toEqual(secondPromise);
|
||||||
|
|
||||||
expect(ngModuleLoader.load).toHaveBeenCalledTimes(1);
|
expect(ngModuleLoader.load).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call the ngModuleLoader twice and return the active request', () => {
|
||||||
|
let resolve: any = null;
|
||||||
|
let reject: any = null;
|
||||||
|
let promise = new Promise((scopedResolved, scopedReject) => {
|
||||||
|
resolve = scopedResolved;
|
||||||
|
reject = scopedReject;
|
||||||
|
});
|
||||||
|
let promise2 = new Promise((scopedResolved, scopedReject) => {
|
||||||
|
resolve = scopedResolved;
|
||||||
|
reject = scopedReject;
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOn(ngModuleLoader, 'load').and.returnValue(promise);
|
||||||
|
|
||||||
|
// Load the first module
|
||||||
|
let pathPrefix = '../some/known/path';
|
||||||
|
let exportSuffix = 'SomeModule';
|
||||||
|
let loadChildren = pathPrefix + '#' + exportSuffix;
|
||||||
|
|
||||||
|
promise = moduleLoader.load(loadChildren);
|
||||||
|
expect(ngModuleLoader.load).toHaveBeenCalledWith(pathPrefix, exportSuffix);
|
||||||
|
|
||||||
|
// Load the second module
|
||||||
|
let pathPrefix2 = '../another/known/path';
|
||||||
|
let exportSuffix2 = 'AnotherModule';
|
||||||
|
let loadChildren2 = pathPrefix2 + '#' + exportSuffix2;
|
||||||
|
|
||||||
|
promise2 = moduleLoader.load(loadChildren2);
|
||||||
|
expect(ngModuleLoader.load).toHaveBeenCalledWith(pathPrefix2, exportSuffix2);
|
||||||
|
|
||||||
|
// Load the first module before the promise has resolved
|
||||||
|
let secondPromise = moduleLoader.load(loadChildren);
|
||||||
|
|
||||||
|
// The promise returned from the first module should be the cached promise
|
||||||
|
expect(promise).toEqual(secondPromise);
|
||||||
|
|
||||||
|
// Load the second module before the promise has resolved
|
||||||
|
let thirdPromise = moduleLoader.load(loadChildren2);
|
||||||
|
|
||||||
|
// The promise returned from the second module should be the cached promise
|
||||||
|
expect(promise2).toEqual(thirdPromise);
|
||||||
|
|
||||||
|
expect(ngModuleLoader.load).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var moduleLoader: ModuleLoader;
|
var moduleLoader: ModuleLoader;
|
||||||
|
Reference in New Issue
Block a user