-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
jest support: ReanimatedEventEmitter throws in a global scope when touched with jest #205
Comments
I would love any advice you could provide to workaround this issue! |
This would also require fixes to avoid global-scope touching of the NativeModule here: |
I have similar issue, I am using Test suite failed to run
I have successfully mocked
But I cannot figure out how to mock I have tried to mock it like this:
But then I get error saying:
|
I have managed to mock it successfully 😁
|
I need to mock Transition for `react-navigation-animated-switch' so my version like this: jest.mock('react-native-reanimated', () => {
const View = require('react-native').View;
return {
Value: jest.fn(),
event: jest.fn(),
add: jest.fn(),
eq: jest.fn(),
set: jest.fn(),
cond: jest.fn(),
interpolate: jest.fn(),
View: View,
Extrapolate: { CLAMP: jest.fn() },
Transition: {
Together: 'Together',
Out: 'Out',
In: 'In',
},
};
}); |
Hi @mralj and @EricMcRay I get the following error after using your mock solution: TypeError: Cannot read property 'out' of undefined |
Is this part of
So in my case whole thing now looks like:
|
If anyone has problems with Jest and
and then:
|
It would be great if the necessary mocking was either automatically hooked up for Jest, or at least if there was a source-file or function we could execute to hook it up. I was originally able to solve this by mocking NativeEventEmitter, but today we're upgrading to react-native 0.62, and I had to re-examine this ticket & thread. For me, it looks like we needed @mralj's answer too: #205 (comment) |
I feel foolish for not figuring this out before now, but the following lines of code in my jest.mock("react-native-reanimated", () =>
jest.requireActual("../../node_modules/react-native-reanimated/mock"),
); Maybe we should add this line to the README or docs somewhere? |
The following line of code is dangerous in a jest environment:
https://github.com/kmagiera/react-native-reanimated/blob/3f9f5cca3bd7867cf9e17147f5e9200567f0cdda/src/ReanimatedEventEmitter.js#L4
Scenario:
I upgraded react-navigation-tabs to a version that started including this library.
Immediately any of my unit tests that happened to import my navigation stack triggered crashes even though I wasn't actually using react-navigation-tabs in my tests.
Callstack
In a jest environment, obviously NativeModules has nothing in it.
Proposal
If we change the EventEmitter to lazily create on first access, this would be safer, possibly?
Thoughts?
The text was updated successfully, but these errors were encountered: