heap / react-native-heap

A React Native integration for Heap
MIT License
81 stars 36 forks source link

Jest mocking instructions #376

Open tomgreco opened 1 year ago

tomgreco commented 1 year ago

How to mock this library to work with jest tests?

Without creating any mock and running jest tests after installing this library I get


/node_modules/@heap/react-native-heap/dist/js/Heap.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { NativeModules } from 'react-native';
SyntaxError: Cannot use import statement outside a module```
Dmitry-GH commented 1 year ago

I mock it like this in my jest setup file: jest.mock('@heap/react-native-heap', () => ({ withReactNavigationAutotrack: jest.fn() }));