Skip to content

Commit 0f6eb72

Browse files
committed
test: decorator utils
1 parent eb53aa8 commit 0f6eb72

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/cli/src/angular/utils/decorator-utils.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import {
77
insertIntoDecoratorArgArray,
88
deleteFromDecoratorArgArray,
99
} from "./decorator-utils";
10+
import exp from "constants";
1011

1112
describe("getDecoratorArgument", () => {
1213
it("should return the decorator argument", () => {
1314
const sourceFileContent = `
1415
@NgModule({
1516
imports: ['foo'],
16-
exports: ['bar']
17+
exports: ['bar'],
18+
declarations: []
1719
})
1820
export class AppModule { }
1921
`;
@@ -25,9 +27,27 @@ describe("getDecoratorArgument", () => {
2527

2628
const imports = getDecoratorArgument(decorator!, "imports");
2729
const exports = getDecoratorArgument(decorator!, "exports");
30+
const declarations = getDecoratorArgument(decorator!, "declarations");
2831

2932
expect(imports?.getText()).toBe(`imports: ['foo']`);
3033
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);
3151
});
3252
});
3353

0 commit comments

Comments
 (0)