-
Notifications
You must be signed in to change notification settings - Fork 93
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
Interface mocks cannot be bound in inversify containers #222
Comments
function isPromise(object) {
var isObjectOrFunction = (typeof object === 'object' && object !== null) || typeof object === 'function';
return isObjectOrFunction && typeof object.then === "function";
}
|
As a work around you can do |
Faced this problem today. function mockInterface<T>(): T {
const mocked = mock<T>();
when((mocked as any).then).thenReturn(undefined);
return mocked;
} |
@NagRock Just encountered the same problem, but unfortunately I didn't see this post soon enough so had to spend a lot of time debugging. Since |
Yeah, also spend a long time to figure this issue out. |
We use
inversify
for IOC (https://inversify.io/). Injecting mocks is an important testing use case for us. However, we found that interface mocks cannot be properly bound in inversify contexts.Here's code combining
inversify
andts-mockito
that shows the problem:After looking into the inversify code, it seems that the problem is that
inversify.isPromise
incorrectly returnstrue
for interface mocks, which makes invetsify try to resolve the mock, resulting in anull
value:The inversify code for
isPromise
is here: https://github.com/inversify/InversifyJS/blob/master/src/utils/async.tsThe text was updated successfully, but these errors were encountered: