Inability to use mocks with rxjs
rraziel opened this issue · comments
Hello,
Very nice library, which works well in a lot of cases, except..
Most of my code involves RxJS observables and I can't do something as simple as
const x = mock<T>();
await lastValueFrom(of(x));
It ends with a timeout due to the implementation of of
in RxJS.
It seems to boil down to RxJS looking for a schedule
property/method on the object passed to of()
, and when that property is present RxJS goes down the "wrong" path thinking a scheduler was passed.
There is already a quick fix for promises in the proxy used by jest-mock-extended: https://github.com/marchaos/jest-mock-extended/blob/master/src/Mock.ts#L91
I don't know if it's feasible to add a similar condition for schedule
, as it might be a legit property/method in code tested by current users...
Hey - I added a way to add configure global ignores - You can try it on this branch - https://github.com/marchaos/jest-mock-extended/tree/global-config-ignore-props
In your global setup file, you can add
import { JestMockExtended } from 'jest-mock-extended';
JestMockExtended.configure({ ignoreProps: 'schedule '});
You could do that in the test file itself (in the beforeEach, and the do JestMockExtended .configure(JestMockExtended.DEFAULT_CONFIG);
in the afterEach
Let me know that helps.
Hello there,
Sorry it took forever, I thought this issue was closed: this solution works just fine 😅