Skip to content

Commit f465fce

Browse files
committed
test(router): cover enum data in feature routes
closes #1334
1 parent 07dbf7a commit f465fce

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎test/src/utils/router-parser.util.spec.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,56 @@ const routes = [
488488

489489
expect(parsed[0].path).to.equal("dynamicPath()");
490490
});
491+
492+
it("should allow enum references in feature-module Route[] data objects (issue #1334)", () => {
493+
const project = new Project({ useInMemoryFileSystem: true });
494+
project.createSourceFile(
495+
"/tmp/user-types.enum.ts",
496+
`
497+
export enum UserTypes {
498+
UserType1 = "UserType1",
499+
UserType2 = "UserType2"
500+
}
501+
`,
502+
);
503+
const sourceFile = project.createSourceFile(
504+
"/tmp/feature-routing.module.ts",
505+
`
506+
import { Route } from "@angular/router";
507+
import { UserTypes } from "./user-types.enum";
508+
509+
const routes: Route[] = [
510+
{
511+
path: "userType2",
512+
component: "UserType2Component",
513+
canActivate: ["RoleGuard"],
514+
data: {
515+
allowedUserTypes: [UserTypes.UserType2]
516+
}
517+
}
518+
];
519+
`,
520+
);
521+
522+
routerParser.cleanFileSpreads(sourceFile);
523+
routerParser.cleanCallExpressions(sourceFile);
524+
routerParser.cleanFileDynamics(sourceFile);
525+
526+
const initializer = sourceFile
527+
.getVariableDeclarationOrThrow("routes")
528+
.getInitializerOrThrow().compilerNode;
529+
const generated = new CodeGenerator().generate(initializer);
530+
const cleaned = routerParser.cleanRawRoute(generated);
531+
532+
let parsed: any;
533+
expect(() => {
534+
parsed = require("json5").parse(cleaned);
535+
}).not.to.throw();
536+
537+
expect(parsed[0].data.allowedUserTypes).to.deep.equal([
538+
"UserType2",
539+
]);
540+
});
491541
});
492542

493543
// ── cleanFileSpreads() — path alias resolution (issue #1545) ─────────────

0 commit comments

Comments
 (0)