I am using Jest and Enzyme for my tests. I have no problem testing normal events but I am struggling to find the correct approach for how to trigger and test events within components that come from Native Modules. In my Jest setup I have the following:
jest.mock('NativeEventEmitter', () => class MockNativeEventEmitter{
addListener = () => jest.fn()
removeListener = () => jest.fn()
removeAllListeners = () => jest.fn()
});
However, I am not sure within the test how I go about actually dispatching an event. So, for example I have a Native module for when the user shakes the device. Within the component itself this is setup like so:
shakeEvents: ['shaken],
deviceShakeEmitter: {},
componentDidMount() {
this.deviceShakeEmitter = new NativeEventEmitter(Shake)
this.deviceShakeEmitter.addListener('shaken', this['shaken'])
},
I know for inbuilt events i can use jest.simulate('press') etc, but for the custom event I am struggling to understand how I approach this within the tests.