I use Jest and Enzyme for my tests. I have no problems testing ordinary events, but I try my best to find the right approach to how to trigger and test events inside 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'm not sure about testing how I go, actually sending an event. So, for example, I have my own module when the user shakes the device. Inside the component itself, this is configured as follows:
shakeEvents: ['shaken], deviceShakeEmitter: {}, componentDidMount() { this.deviceShakeEmitter = new NativeEventEmitter(Shake) this.deviceShakeEmitter.addListener('shaken', this['shaken']) },
I know that for embedded events, I can use jest.simulate ('press'), etc., but for a custom event, I am struggling to understand how I approach this in tests.
source share