dpa99c / react-native-launch-navigator

A React Native module for launching today's most popular navigation/ride apps to navigate to a destination.
143 stars 34 forks source link

[FEATURE] support Jest mocking #22

Open vovkind opened 4 years ago

vovkind commented 4 years ago

I'm submitting a ... (check one with "x"):

Bug report

Current behavior:

Unable to mock the plugin as part of unit testing. Tried to mock the plugin as following: jest.mock('react-native-launch-navigator', () => 'LaunchNavigator');

Getting exception on running npm test:

● Test suite failed to run

Invariant Violation: Native module cannot be null.

  23 | import Sound from 'react-native-sound';
> 24 | import LaunchNavigator from 'react-native-launch-navigator';
     |                                                          ^

  at invariant (node_modules/invariant/invariant.js:40:15)
  at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:36:27)
  at RNLogger._addListeners (node_modules/react-native-launch-navigator/RNLogger.js:11:33)
  at new RNLogger (node_modules/react-native-launch-navigator/RNLogger.js:48:10)
  at Object.<anonymous> (node_modules/react-native-launch-navigator/index.js:24:14)
  at Object.<anonymous> (src/utils/CommonFunctions.js:24:58)

Mocking of plugin is not working

Expected behavior:

Unit testing with Jest should work

Mocking of the plugin should be successfully performed.

Steps to reproduce:

npm test

with some code containing import to react-native-launch-navigator

Environment information

Console output

console output ``` // Paste any relevant JS/native console output here ```


dpa99c commented 4 years ago

I consider this a feature request, not a bug because the module actually works fine in reality, it just doesn't currently support mocking of its functionality.