Skip to content

Commit 9a1cc63

Browse files
committed
test(router): cover resolve inject callbacks
closes #1433
1 parent f465fce commit 9a1cc63

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
@@ -538,6 +538,44 @@ const routes: Route[] = [
538538
"UserType2",
539539
]);
540540
});
541+
542+
it("should allow resolve callbacks using inject() in feature Route[] declarations (issue #1433)", () => {
543+
const project = new Project({ useInMemoryFileSystem: true });
544+
const sourceFile = project.createSourceFile(
545+
"/tmp/people-routing.module.ts",
546+
`
547+
import { Route } from "@angular/router";
548+
549+
const routes: Route[] = [
550+
{
551+
path: "",
552+
component: "PersonListComponent",
553+
canActivate: ["AuthGuard"],
554+
resolve: {
555+
personListLink: () => inject(PersonListResolver).resolvePersonListLink()
556+
}
557+
}
558+
];
559+
`,
560+
);
561+
562+
routerParser.cleanFileSpreads(sourceFile);
563+
routerParser.cleanCallExpressions(sourceFile);
564+
routerParser.cleanFileDynamics(sourceFile);
565+
566+
const initializer = sourceFile
567+
.getVariableDeclarationOrThrow("routes")
568+
.getInitializerOrThrow().compilerNode;
569+
const generated = new CodeGenerator().generate(initializer);
570+
const cleaned = routerParser.cleanRawRoute(generated);
571+
572+
let parsed: any;
573+
expect(() => {
574+
parsed = require("json5").parse(cleaned);
575+
}).not.to.throw();
576+
577+
expect(parsed[0].resolve.personListLink).to.equal("[Function]");
578+
});
541579
});
542580

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

0 commit comments

Comments
 (0)