-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve support for mocking dependencies in DI #32
Conversation
|
||
declare module 'awilix' { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
interface ResolverOptions<T> { | ||
asyncInit?: boolean | string | ||
asyncInitPriority?: number // lower means it gets initted earlier | ||
asyncDispose?: boolean | string | ((instance: T) => Promise<unknown>) | ||
asyncDispose?: boolean | string | (<U extends T>(instance: U) => Promise<unknown>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this change it wasn't possible to pass a class that would extend the original class as a resolver override.
E. g. something like this:
consumerErrorResolver: asClass(FakeConsumerErrorResolver, SINGLETON_CONFIG),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I was just writing up a repro for this! https://codesandbox.io/p/devbox/awilix-ts-interface-j5sll2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wahahaha, awesome!
[Key in keyof TDependencies]: Resolver<TDependencies[Key]> | ||
} | ||
|
||
export function asMockClass<T = object>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for cases when we know that passed class does not fully implement the original class contract, and we are fine with that.
No description provided.