@@ -50,47 +50,47 @@ describe('Directive Schematic', () => {
50
50
51
51
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
52
52
const files = tree . files ;
53
- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.directive. spec.ts' ) ;
54
- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.directive. ts' ) ;
53
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.spec.ts' ) ;
54
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.ts' ) ;
55
55
} ) ;
56
56
57
57
it ( 'should converts dash-cased-name to a camelCasedSelector' , async ( ) => {
58
58
const options = { ...defaultOptions , name : 'my-dir' } ;
59
59
60
60
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
61
- const content = tree . readContent ( '/projects/bar/src/app/my-dir.directive. ts' ) ;
61
+ const content = tree . readContent ( '/projects/bar/src/app/my-dir.ts' ) ;
62
62
expect ( content ) . toMatch ( / s e l e c t o r : ' \[ a p p M y D i r \] ' / ) ;
63
63
} ) ;
64
64
65
65
it ( 'should create the right selector with a path in the name' , async ( ) => {
66
66
const options = { ...defaultOptions , name : 'sub/test' } ;
67
67
appTree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
68
68
69
- const content = appTree . readContent ( '/projects/bar/src/app/sub/test.directive. ts' ) ;
69
+ const content = appTree . readContent ( '/projects/bar/src/app/sub/test.ts' ) ;
70
70
expect ( content ) . toMatch ( / s e l e c t o r : ' \[ a p p T e s t \] ' / ) ;
71
71
} ) ;
72
72
73
73
it ( 'should use the prefix' , async ( ) => {
74
74
const options = { ...defaultOptions , prefix : 'pre' } ;
75
75
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
76
76
77
- const content = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
77
+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
78
78
expect ( content ) . toMatch ( / s e l e c t o r : ' \[ p r e F o o \] ' / ) ;
79
79
} ) ;
80
80
81
81
it ( 'should use the default project prefix if none is passed' , async ( ) => {
82
82
const options = { ...defaultOptions , prefix : undefined } ;
83
83
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
84
84
85
- const content = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
85
+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
86
86
expect ( content ) . toMatch ( / s e l e c t o r : ' \[ a p p F o o \] ' / ) ;
87
87
} ) ;
88
88
89
89
it ( 'should use the supplied prefix if it is ""' , async ( ) => {
90
90
const options = { ...defaultOptions , prefix : '' } ;
91
91
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
92
92
93
- const content = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
93
+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
94
94
expect ( content ) . toMatch ( / s e l e c t o r : ' \[ f o o \] ' / ) ;
95
95
} ) ;
96
96
@@ -99,16 +99,16 @@ describe('Directive Schematic', () => {
99
99
100
100
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
101
101
const files = tree . files ;
102
- expect ( files ) . toContain ( '/projects/bar/src/app/foo.directive. ts' ) ;
103
- expect ( files ) . not . toContain ( '/projects/bar/src/app/foo.directive. spec.ts' ) ;
102
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo.ts' ) ;
103
+ expect ( files ) . not . toContain ( '/projects/bar/src/app/foo.spec.ts' ) ;
104
104
} ) ;
105
105
106
106
it ( 'should create a standalone directive' , async ( ) => {
107
107
const options = { ...defaultOptions , standalone : true } ;
108
108
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
109
- const directiveContent = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
109
+ const directiveContent = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
110
110
expect ( directiveContent ) . not . toContain ( 'standalone' ) ;
111
- expect ( directiveContent ) . toContain ( 'class FooDirective ' ) ;
111
+ expect ( directiveContent ) . toContain ( 'class Foo ' ) ;
112
112
} ) ;
113
113
114
114
it ( 'should error when class name contains invalid characters' , async ( ) => {
@@ -119,6 +119,24 @@ describe('Directive Schematic', () => {
119
119
) . toBeRejectedWithError ( 'Class name "404" is invalid.' ) ;
120
120
} ) ;
121
121
122
+ it ( 'should respect the type option' , async ( ) => {
123
+ const options = { ...defaultOptions , type : 'Directive' } ;
124
+ const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
125
+ const content = tree . readContent ( '/projects/bar/src/app/foo.directive.ts' ) ;
126
+ const testContent = tree . readContent ( '/projects/bar/src/app/foo.directive.spec.ts' ) ;
127
+ expect ( content ) . toContain ( 'export class FooDirective' ) ;
128
+ expect ( testContent ) . toContain ( "describe('FooDirective'" ) ;
129
+ } ) ;
130
+
131
+ it ( 'should allow empty string in the type option' , async ( ) => {
132
+ const options = { ...defaultOptions , type : '' } ;
133
+ const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
134
+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
135
+ const testContent = tree . readContent ( '/projects/bar/src/app/foo.spec.ts' ) ;
136
+ expect ( content ) . toContain ( 'export class Foo' ) ;
137
+ expect ( testContent ) . toContain ( "describe('Foo'" ) ;
138
+ } ) ;
139
+
122
140
describe ( 'standalone=false' , ( ) => {
123
141
const defaultNonStandaloneOptions : DirectiveOptions = {
124
142
...defaultOptions ,
@@ -139,11 +157,11 @@ describe('Directive Schematic', () => {
139
157
140
158
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
141
159
const files = tree . files ;
142
- expect ( files ) . toContain ( '/projects/baz/src/app/foo.directive. spec.ts' ) ;
143
- expect ( files ) . toContain ( '/projects/baz/src/app/foo.directive. ts' ) ;
160
+ expect ( files ) . toContain ( '/projects/baz/src/app/foo.spec.ts' ) ;
161
+ expect ( files ) . toContain ( '/projects/baz/src/app/foo.ts' ) ;
144
162
const moduleContent = tree . readContent ( '/projects/baz/src/app/app.module.ts' ) ;
145
- expect ( moduleContent ) . toMatch ( / i m p o r t .* F o o .* f r o m ' .\/ f o o . d i r e c t i v e ' / ) ;
146
- expect ( moduleContent ) . toMatch ( / d e c l a r a t i o n s : \s * \[ [ ^ \] ] + ?, \r ? \n \s + F o o D i r e c t i v e \r ? \n / m) ;
163
+ expect ( moduleContent ) . toMatch ( / i m p o r t .* F o o .* f r o m ' .\/ f o o ' / ) ;
164
+ expect ( moduleContent ) . toMatch ( / d e c l a r a t i o n s : \s * \[ [ ^ \] ] + ?, \r ? \n \s + F o o \r ? \n / m) ;
147
165
} ) ;
148
166
149
167
it ( 'should respect the sourceRoot value' , async ( ) => {
@@ -167,7 +185,7 @@ describe('Directive Schematic', () => {
167
185
appTree ,
168
186
) ;
169
187
170
- expect ( appTree . files ) . toContain ( '/projects/baz/custom/app/foo.directive. ts' ) ;
188
+ expect ( appTree . files ) . toContain ( '/projects/baz/custom/app/foo.ts' ) ;
171
189
} ) ;
172
190
173
191
it ( 'should find the closest module' , async ( ) => {
@@ -188,15 +206,15 @@ describe('Directive Schematic', () => {
188
206
189
207
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
190
208
const fooModuleContent = tree . readContent ( fooModule ) ;
191
- expect ( fooModuleContent ) . toMatch ( / i m p o r t { F o o D i r e c t i v e } f r o m ' .\/ f o o . d i r e c t i v e ' / ) ;
209
+ expect ( fooModuleContent ) . toMatch ( / i m p o r t { F o o } f r o m ' .\/ f o o ' / ) ;
192
210
} ) ;
193
211
194
212
it ( 'should export the directive' , async ( ) => {
195
213
const options = { ...defaultNonStandaloneOptions , export : true } ;
196
214
197
215
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
198
216
const appModuleContent = tree . readContent ( '/projects/baz/src/app/app.module.ts' ) ;
199
- expect ( appModuleContent ) . toMatch ( / e x p o r t s : \[ \n ( \s * ) { 2 } F o o D i r e c t i v e \n \1\] / ) ;
217
+ expect ( appModuleContent ) . toMatch ( / e x p o r t s : \[ \n ( \s * ) { 2 } F o o \n \1\] / ) ;
200
218
} ) ;
201
219
202
220
it ( 'should import into a specified module' , async ( ) => {
@@ -205,7 +223,7 @@ describe('Directive Schematic', () => {
205
223
const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
206
224
const appModule = tree . readContent ( '/projects/baz/src/app/app.module.ts' ) ;
207
225
208
- expect ( appModule ) . toMatch ( / i m p o r t { F o o D i r e c t i v e } f r o m ' .\/ f o o . d i r e c t i v e ' / ) ;
226
+ expect ( appModule ) . toMatch ( / i m p o r t { F o o } f r o m ' .\/ f o o ' / ) ;
209
227
} ) ;
210
228
211
229
it ( 'should fail if specified module does not exist' , async ( ) => {
0 commit comments