I tried to run default test in react-native using jest and I found this problem:
Test suite failed to run
Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.
at invariant (node_modules/invariant/invariant.js:40:15)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:44:7)
at Object.<anonymous> (node_modules/@react-native-clipboard/clipboard/dist/NativeClipboard.js:15:20)
at Object.<anonymous> (node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js:24:38)
I completly dont know how to solve this problem.
Ive tried to add the following line:
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
to jest.setup.js
or
mocks/native_event_emmiter.js
but neither solution works.
Anyone know how to solve this ?
Have you add setupFiles in your jest.config.js?
This worked for me:
//jest.config.js
setupFiles: ['<rootDir>/jest.setup.js'],
//jest.setup.js
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With