Skip to content

Commit 1c9a7c4

Browse files
committed
test: cover nativeModules fallback when the native side is missing
1 parent 0f5eaab commit 1c9a7c4

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

__tests__/nativeModules.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Tests that importing the native module bindings does not throw when the
3+
* native side is unavailable (Expo Go, Jest, web bundles, prebuilds before
4+
* pods are installed).
5+
*/
6+
7+
describe('nativeModules', () => {
8+
afterEach(() => {
9+
jest.resetModules();
10+
jest.dontMock('react-native');
11+
});
12+
13+
test('falls back to empty objects when native modules are missing', () => {
14+
jest.doMock('react-native', () => ({
15+
NativeModules: {},
16+
TurboModuleRegistry: { get: () => null },
17+
}));
18+
19+
let modules: typeof import('../src/nativeModules') | undefined;
20+
expect(() => {
21+
modules = require('../src/nativeModules');
22+
}).not.toThrow();
23+
24+
expect(modules?.IntercomModule).toEqual({});
25+
expect(modules?.IntercomEventEmitter).toEqual({});
26+
});
27+
28+
test('uses the registered native modules when they are available', () => {
29+
const intercomModule = { initialize: jest.fn() };
30+
const intercomEventEmitter = { UNREAD_COUNT_CHANGE_NOTIFICATION: 'event' };
31+
32+
jest.doMock('react-native', () => ({
33+
NativeModules: {
34+
IntercomModule: intercomModule,
35+
IntercomEventEmitter: intercomEventEmitter,
36+
},
37+
TurboModuleRegistry: { get: () => null },
38+
}));
39+
40+
const modules = require('../src/nativeModules');
41+
42+
expect(modules.IntercomModule).toBe(intercomModule);
43+
expect(modules.IntercomEventEmitter).toBe(intercomEventEmitter);
44+
});
45+
});

0 commit comments

Comments
 (0)