I use ts-mockito to test my NestJs application. Basically it works very well, but there are problems if the word "then" is somewhere in the code. If the word "then" is present, the created proxy object is assigned a function "then". When using NestJs with Jest, this leads to a timeout when using the mock by overriding a provider for dependency injection.
export class Foo {
myFunction(): Promise<string> {
return Promise.resolve().then(() => {
return 'foo';
});
}
}
const mockedFoo = mock(Foo);
const foo = instance(mockedFoo);
Results in:

It is also very strange that the Promise functions (then, resolve) are also added as a function on the proxy when the corresponding code has been commented out, but is inside a block of a function!
export class Foo {
myFunction(): Promise<string> {
return Promise.resolve('foo');
// return Promise.resolve().then(() => {
// return 'foo';
// });
}
}
const mockedFoo = mock(Foo);
const foo = instance(mockedFoo);
Results in:

As a workaround to be able to use the mocks with NestJs Dependency Injection, I remove the then property from the proxy:
delete foo['then']
I use ts-mockito to test my NestJs application. Basically it works very well, but there are problems if the word "then" is somewhere in the code. If the word "then" is present, the created proxy object is assigned a function "then". When using NestJs with Jest, this leads to a timeout when using the mock by overriding a provider for dependency injection.
Results in:

It is also very strange that the Promise functions (then, resolve) are also added as a function on the proxy when the corresponding code has been commented out, but is inside a block of a function!
Results in:

As a workaround to be able to use the mocks with NestJs Dependency Injection, I remove the then property from the proxy:
delete foo['then']