Skip to content

Commit 05365f0

Browse files
committed
test(router): cover enum outlet route values
closes #1335
1 parent b5b44da commit 05365f0

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,44 @@ const routes: Routes = [
345345
});
346346
});
347347

348+
describe("cleanFileDynamics() — enum values in route outlet (issue #1335)", () => {
349+
it("should resolve enum member values used as outlet and stay JSON5-parseable", () => {
350+
const project = new Project({ useInMemoryFileSystem: true });
351+
const sourceFile = project.createSourceFile(
352+
"/tmp/routes-1335.ts",
353+
`
354+
import { Routes } from "@angular/router";
355+
356+
export enum MyRoutes {
357+
RouteOne = "one",
358+
RouteTwo = "two",
359+
RouteThree = "three",
360+
RouteFour = "four"
361+
}
362+
363+
const routes: Routes = [
364+
{ path: "", component: "MyComponent", outlet: MyRoutes.RouteFour }
365+
];
366+
`,
367+
);
368+
369+
routerParser.cleanCallExpressions(sourceFile);
370+
routerParser.cleanFileDynamics(sourceFile);
371+
372+
const initializer = sourceFile
373+
.getVariableDeclarationOrThrow("routes")
374+
.getInitializerOrThrow().compilerNode;
375+
const generated = new CodeGenerator().generate(initializer);
376+
const cleaned = routerParser.cleanRawRoute(generated);
377+
378+
let parsed: any;
379+
expect(() => {
380+
parsed = require("json5").parse(cleaned);
381+
}).not.to.throw();
382+
expect(parsed[0].outlet).to.equal("four");
383+
});
384+
});
385+
348386
describe("cleanCallExpressions() — function calls in route values (issue #1293)", () => {
349387
it("should allow JSON5.parse when path is defined by a function call", () => {
350388
const project = new Project({ useInMemoryFileSystem: true });

0 commit comments

Comments
 (0)