remobile / react-native-file-transfer

A file-transfer for react-native, code come from cordova, support for android and ios
MIT License
85 stars 22 forks source link

Jest Native Events #8

Open sam-n-johnston opened 7 years ago

sam-n-johnston commented 7 years ago

This package works great and thanks a lot for that!

The problem I have is when I try to run tests with Jest on my code. When I run the tests, I get the following error message:

Invariant Violation: Native module cannot be null.

      at invariant (node_modules\fbjs\lib\invariant.js:38:15)
      at new NativeEventEmitter (node_modules\react-native\Libraries\EventEmitter\NativeEventEmitter.js:32:1)
      at Object.<anonymous> (node_modules\@remobile\react-native-file-transfer\libs\FileTransfer.js:29:63)
      at Object.<anonymous> (node_modules\@remobile\react-native-file-transfer\index.js:2:20)

The line in my code that is the culprit is: import FileTransfer from '@remobile/react-native-file-transfer' I've tried mocking the the module with Jest, but this does not fix the error.

The problem is caused by line 29 in FileTransfer.js: var EventEmitter = Platform.OS==="android"?DeviceEventEmitter:new NativeEventEmitter(NativeModules.FileTransfer);

Can anyone help me with this error? Thanks.