|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
| 9 | +import {global} from '@angular/common/src/facade/lang'; |
9 | 10 | import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
|
10 | 11 | import {async, tick} from '@angular/core/testing';
|
11 |
| -import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal'; |
| 12 | +import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal'; |
12 | 13 |
|
13 |
| -function mockSystem(module: string, contents: any) { |
| 14 | +function mockSystem(modules: {[module: string]: any}) { |
14 | 15 | return {
|
15 | 16 | 'import': (target: string) => {
|
16 |
| - expect(target).toBe(module); |
17 |
| - return Promise.resolve(contents); |
| 17 | + expect(modules[target]).not.toBe(undefined); |
| 18 | + return Promise.resolve(modules[target]); |
18 | 19 | }
|
19 | 20 | };
|
20 | 21 | }
|
21 | 22 |
|
22 | 23 | export function main() {
|
23 | 24 | describe('SystemJsNgModuleLoader', () => {
|
| 25 | + let oldSystem: any = null; |
| 26 | + beforeEach(() => { |
| 27 | + oldSystem = (global as any).System; |
| 28 | + (global as any).System = mockSystem({ |
| 29 | + 'test.ngfactory': |
| 30 | + {'default': 'test module factory', 'NamedNgFactory': 'test NamedNgFactory'}, |
| 31 | + 'prefixed/test/suffixed': {'NamedNgFactory': 'test module factory'} |
| 32 | + }); |
| 33 | + }); |
| 34 | + afterEach(() => { (global as any).System = oldSystem; }); |
| 35 | + |
24 | 36 | it('loads a default factory by appending the factory suffix', async(() => {
|
25 | 37 | let loader = new SystemJsNgModuleLoader(new Compiler());
|
26 |
| - loader._system = () => mockSystem('test.ngfactory', {'default': 'test module factory'}); |
27 | 38 | loader.load('test').then(contents => { expect(contents).toBe('test module factory'); });
|
28 | 39 | }));
|
29 | 40 | it('loads a named factory by appending the factory suffix', async(() => {
|
30 | 41 | let loader = new SystemJsNgModuleLoader(new Compiler());
|
31 |
| - loader._system = () => |
32 |
| - mockSystem('test.ngfactory', {'NamedNgFactory': 'test module factory'}); |
33 | 42 | loader.load('test#Named').then(contents => {
|
34 |
| - expect(contents).toBe('test module factory'); |
| 43 | + expect(contents).toBe('test NamedNgFactory'); |
35 | 44 | });
|
36 | 45 | }));
|
37 | 46 | it('loads a named factory with a configured prefix and suffix', async(() => {
|
38 | 47 | let loader = new SystemJsNgModuleLoader(new Compiler(), {
|
39 | 48 | factoryPathPrefix: 'prefixed/',
|
40 | 49 | factoryPathSuffix: '/suffixed',
|
41 | 50 | });
|
42 |
| - loader._system = () => |
43 |
| - mockSystem('prefixed/test/suffixed', {'NamedNgFactory': 'test module factory'}); |
44 | 51 | loader.load('test#Named').then(contents => {
|
45 | 52 | expect(contents).toBe('test module factory');
|
46 | 53 | });
|
|
0 commit comments