@@ -50,47 +50,47 @@ describe('Directive Schematic', () => {
5050
5151 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
5252 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' ) ;
5555 } ) ;
5656
5757 it ( 'should converts dash-cased-name to a camelCasedSelector' , async ( ) => {
5858 const options = { ...defaultOptions , name : 'my-dir' } ;
5959
6060 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' ) ;
6262 expect ( content ) . toMatch ( / s e l e c t o r : ' \[ a p p M y D i r \] ' / ) ;
6363 } ) ;
6464
6565 it ( 'should create the right selector with a path in the name' , async ( ) => {
6666 const options = { ...defaultOptions , name : 'sub/test' } ;
6767 appTree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
6868
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' ) ;
7070 expect ( content ) . toMatch ( / s e l e c t o r : ' \[ a p p T e s t \] ' / ) ;
7171 } ) ;
7272
7373 it ( 'should use the prefix' , async ( ) => {
7474 const options = { ...defaultOptions , prefix : 'pre' } ;
7575 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
7676
77- const content = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
77+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
7878 expect ( content ) . toMatch ( / s e l e c t o r : ' \[ p r e F o o \] ' / ) ;
7979 } ) ;
8080
8181 it ( 'should use the default project prefix if none is passed' , async ( ) => {
8282 const options = { ...defaultOptions , prefix : undefined } ;
8383 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
8484
85- const content = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
85+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
8686 expect ( content ) . toMatch ( / s e l e c t o r : ' \[ a p p F o o \] ' / ) ;
8787 } ) ;
8888
8989 it ( 'should use the supplied prefix if it is ""' , async ( ) => {
9090 const options = { ...defaultOptions , prefix : '' } ;
9191 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
9292
93- const content = tree . readContent ( '/projects/bar/src/app/foo.directive. ts' ) ;
93+ const content = tree . readContent ( '/projects/bar/src/app/foo.ts' ) ;
9494 expect ( content ) . toMatch ( / s e l e c t o r : ' \[ f o o \] ' / ) ;
9595 } ) ;
9696
@@ -99,16 +99,16 @@ describe('Directive Schematic', () => {
9999
100100 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
101101 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' ) ;
104104 } ) ;
105105
106106 it ( 'should create a standalone directive' , async ( ) => {
107107 const options = { ...defaultOptions , standalone : true } ;
108108 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' ) ;
110110 expect ( directiveContent ) . not . toContain ( 'standalone' ) ;
111- expect ( directiveContent ) . toContain ( 'class FooDirective ' ) ;
111+ expect ( directiveContent ) . toContain ( 'class Foo ' ) ;
112112 } ) ;
113113
114114 it ( 'should error when class name contains invalid characters' , async ( ) => {
@@ -119,6 +119,24 @@ describe('Directive Schematic', () => {
119119 ) . toBeRejectedWithError ( 'Class name "404" is invalid.' ) ;
120120 } ) ;
121121
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+
122140 describe ( 'standalone=false' , ( ) => {
123141 const defaultNonStandaloneOptions : DirectiveOptions = {
124142 ...defaultOptions ,
@@ -139,11 +157,11 @@ describe('Directive Schematic', () => {
139157
140158 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
141159 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' ) ;
144162 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) ;
147165 } ) ;
148166
149167 it ( 'should respect the sourceRoot value' , async ( ) => {
@@ -167,7 +185,7 @@ describe('Directive Schematic', () => {
167185 appTree ,
168186 ) ;
169187
170- expect ( appTree . files ) . toContain ( '/projects/baz/custom/app/foo.directive. ts' ) ;
188+ expect ( appTree . files ) . toContain ( '/projects/baz/custom/app/foo.ts' ) ;
171189 } ) ;
172190
173191 it ( 'should find the closest module' , async ( ) => {
@@ -188,15 +206,15 @@ describe('Directive Schematic', () => {
188206
189207 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
190208 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 ' / ) ;
192210 } ) ;
193211
194212 it ( 'should export the directive' , async ( ) => {
195213 const options = { ...defaultNonStandaloneOptions , export : true } ;
196214
197215 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
198216 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\] / ) ;
200218 } ) ;
201219
202220 it ( 'should import into a specified module' , async ( ) => {
@@ -205,7 +223,7 @@ describe('Directive Schematic', () => {
205223 const tree = await schematicRunner . runSchematic ( 'directive' , options , appTree ) ;
206224 const appModule = tree . readContent ( '/projects/baz/src/app/app.module.ts' ) ;
207225
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 ' / ) ;
209227 } ) ;
210228
211229 it ( 'should fail if specified module does not exist' , async ( ) => {
0 commit comments