0

I want something like the following (that actually works...):

import { NativeModules } from 'react-native';
import PushNotifications from '../../app/platform/PushNotificationSupport';


const mockRNA = jest.requireMock('react-native');
jest.mock('react-native', () => {
    return {
        default: mockRNA.default,
        NativeModules: {
            ...mockRNA.NativeModules,
            NativePushNotifications: {
                setTokenHandler: jest.fn(),
            },
        },
    };
});

Of course, the above code doesn't actually work. I essentially want to build on top of the existing react-native mock.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
codecitrus
  • 659
  • 6
  • 17

1 Answers1

0

You can try to mock NativeModules directly

jest.mock('NativeModules', () => ({
    NativePushNotifications: {
        setTokenHandler: jest.fn(),
    },
    ...
}));
Ewe Tek Min
  • 855
  • 10
  • 19