@@ -7,13 +7,15 @@ import {
7
7
insertIntoDecoratorArgArray ,
8
8
deleteFromDecoratorArgArray ,
9
9
} from "./decorator-utils" ;
10
+ import exp from "constants" ;
10
11
11
12
describe ( "getDecoratorArgument" , ( ) => {
12
13
it ( "should return the decorator argument" , ( ) => {
13
14
const sourceFileContent = `
14
15
@NgModule({
15
16
imports: ['foo'],
16
- exports: ['bar']
17
+ exports: ['bar'],
18
+ declarations: []
17
19
})
18
20
export class AppModule { }
19
21
` ;
@@ -25,9 +27,27 @@ describe("getDecoratorArgument", () => {
25
27
26
28
const imports = getDecoratorArgument ( decorator ! , "imports" ) ;
27
29
const exports = getDecoratorArgument ( decorator ! , "exports" ) ;
30
+ const declarations = getDecoratorArgument ( decorator ! , "declarations" ) ;
28
31
29
32
expect ( imports ?. getText ( ) ) . toBe ( `imports: ['foo']` ) ;
30
33
expect ( exports ?. getText ( ) ) . toBe ( `exports: ['bar']` ) ;
34
+ expect ( declarations ?. getText ( ) ) . toBe ( `declarations: []` ) ;
35
+ } ) ;
36
+
37
+ it ( "should return undefined if the decorator does not have arguments" , ( ) => {
38
+ const sourceFileContent = `
39
+ @NgModule()
40
+ export class AppModule { }
41
+ ` ;
42
+
43
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
44
+ const sourceFile = project . createSourceFile ( "foo.ts" , sourceFileContent ) ;
45
+
46
+ const decorator = sourceFile . getClasses ( ) [ 0 ] ?. getDecorator ( "NgModule" ) ;
47
+
48
+ const imports = getDecoratorArgument ( decorator ! , "imports" ) ;
49
+
50
+ expect ( imports ) . toBe ( undefined ) ;
31
51
} ) ;
32
52
} ) ;
33
53
0 commit comments