Open chapati23 opened 7 years ago
Found a workaround. In case anyone else runs into this:
import mockery from 'mockery'
import * as rn from 'react-native'
mockery.registerMock('react-native', {
...rn,
NativeModules: {
MyBridge: {
nativeCall: () => {}
}
}
})
This feels a bit dirty though. So leaving this open to wait for some feedback if there's a better way to do it.
@chapati23 it's not really clear from your snippets, but remember the first arg of registerMock
has to be exactly what's inside require()
, not just a path to the file you want to mock. Are you doing this?
@RealOrangeOne not sure i understand. in this case i'm mocking the actual react-native
npm package so it does work like it's in the snippet
My Module:
My Mock:
Expected Behavior MyBridge.nativeCall is mocked
Actual Behavior Error message during test run
Error: Cannot read property 'nativeCall' of undefined
I can't, for the life of me, figure this out. Mocking 3rd party modules works fine. Any ideas? (mockery@2.0.0)