Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(di): fix intercept stored token on context.target #2940

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/di/src/common/decorators/intercept.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {catchError} from "@tsed/core";
import {catchError, classOf, nameOf} from "@tsed/core";

import {DITest} from "../../node/index.js";
import {InterceptorContext} from "../interfaces/InterceptorContext.js";
Expand All @@ -13,6 +13,8 @@ class MyInterceptor implements InterceptorMethods {
const r = typeof context.args[0] === "string" ? undefined : new Error(`Error message`);
const retValue = context.next(r);

expect(nameOf(context.target)).toContain("Service");

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider a more precise assertion for context.target

While checking for "Service" works, it would be more robust to verify the exact class name matches the expected service class.

Consider updating the assertion to be more specific:

-expect(nameOf(context.target)).toContain("Service");
+expect(nameOf(context.target)).toBe("ServiceTest");

Committable suggestion skipped: line range outside the PR's diff.

return `${retValue} - ${context.options || ""} - intercepted 1`;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/common/decorators/intercept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function bindIntercept(target: any, propertyKey: string | symbol, token:
};

const context: InterceptorContext<any> = {
target,
target: klass,
propertyKey,
args,
options,
Expand Down
Loading