1
1
import { ComponentFactoryResolver } from '@angular/core' ;
2
+ import * as ngCore from '@angular/core' ;
2
3
import { TestBed } from '@angular/core/testing' ;
3
4
5
+ import { spyOnModule } from '../../test/spy-on-module' ;
4
6
import { HostGeneratorService } from './host-generator.service' ;
7
+ import * as tplGen from './template-gen' ;
5
8
import {
6
9
ExtraConfigToken ,
7
10
TestModuleToken ,
@@ -10,7 +13,6 @@ import {
10
13
} from './tokens' ;
11
14
import { TestTypeKind } from './types' ;
12
15
import * as util from './util' ;
13
- import * as tplGen from './template-gen' ;
14
16
15
17
class TestModuleTokenMock { }
16
18
class TestTypeTokenMock { }
@@ -33,11 +35,74 @@ describe('Service: HostGenerator', () => {
33
35
} ) ;
34
36
35
37
describe ( 'generateModuleFor() method' , ( ) => {
38
+ let ngModule : jasmine . Spy ;
39
+
40
+ beforeEach ( ( ) => {
41
+ getService ( ) ;
42
+ ngModule = spyOnModule ( ngCore , 'NgModule' ) ;
43
+ } ) ;
44
+
36
45
it ( 'should return new type' , ( ) => {
37
46
expect ( getService ( ) . generateModuleFor ( class { } ) ) . toEqual (
38
47
jasmine . any ( Function ) ,
39
48
) ;
40
49
} ) ;
50
+
51
+ it ( 'should import `this.testModule`' , ( ) => {
52
+ getService ( ) . generateModuleFor ( class { } ) ;
53
+
54
+ expect ( ngModule ) . toHaveBeenCalledWith (
55
+ jasmine . objectContaining ( {
56
+ imports : [ TestModuleTokenMock ] ,
57
+ } ) ,
58
+ ) ;
59
+ } ) ;
60
+
61
+ it ( 'should declare `host`' , ( ) => {
62
+ const host = class { } ;
63
+ getService ( ) . generateModuleFor ( host ) ;
64
+
65
+ expect ( ngModule ) . toHaveBeenCalledWith (
66
+ jasmine . objectContaining ( {
67
+ declarations : [ host ] ,
68
+ } ) ,
69
+ ) ;
70
+ } ) ;
71
+
72
+ it ( 'should export `host`' , ( ) => {
73
+ const host = class { } ;
74
+ getService ( ) . generateModuleFor ( host ) ;
75
+
76
+ expect ( ngModule ) . toHaveBeenCalledWith (
77
+ jasmine . objectContaining ( {
78
+ exports : [ host ] ,
79
+ } ) ,
80
+ ) ;
81
+ } ) ;
82
+
83
+ it ( 'should set `host` as entryComponents' , ( ) => {
84
+ const host = class { } ;
85
+ getService ( ) . generateModuleFor ( host ) ;
86
+
87
+ expect ( ngModule ) . toHaveBeenCalledWith (
88
+ jasmine . objectContaining ( {
89
+ entryComponents : [ host ] ,
90
+ } ) ,
91
+ ) ;
92
+ } ) ;
93
+
94
+ it ( 'should set schemas from `this.extraConfig.ngModule.schemas`' , ( ) => {
95
+ const extraConfig = TestBed . get ( ExtraConfigToken ) ;
96
+ extraConfig . ngModule = { schemas : 'schema' } ;
97
+
98
+ getService ( ) . generateModuleFor ( class { } ) ;
99
+
100
+ expect ( ngModule ) . toHaveBeenCalledWith (
101
+ jasmine . objectContaining ( {
102
+ schemas : 'schema' ,
103
+ } ) ,
104
+ ) ;
105
+ } ) ;
41
106
} ) ;
42
107
43
108
describe ( 'generate() method' , ( ) => {
0 commit comments