1import NativeModulesProxy from '../NativeModulesProxy';
2
3jest.mock('react-native', () => {
4  const ReactNative = jest.requireActual('react-native');
5  // Mock a natively defined test module
6  ReactNative.NativeModules.NativeUnimoduleProxy.modulesConstants = {
7    ExpoTest: { testConstant: 'test' },
8  };
9  ReactNative.NativeModules.NativeUnimoduleProxy.exportedMethods = {
10    ...ReactNative.NativeModules.NativeUnimoduleProxy.exportedMethods,
11    ExpoTest: [{ key: 0, name: 'testAsync', argumentsCount: 1 }],
12  };
13  return ReactNative;
14});
15
16it(`has an entry with each native module's constants and methods`, () => {
17  expect(NativeModulesProxy).toHaveProperty('ExpoTest');
18  expect(NativeModulesProxy.ExpoTest.testConstant).toBe('test');
19  expect(typeof NativeModulesProxy.ExpoTest.testAsync).toBe('function');
20});
21
22it(`checks the number of arguments passed to bridged methods`, async () => {
23  await expect(NativeModulesProxy.ExpoTest.testAsync('a')).resolves.not.toThrow();
24  await expect(NativeModulesProxy.ExpoTest.testAsync()).rejects.toThrowErrorMatchingSnapshot();
25  await expect(
26    NativeModulesProxy.ExpoTest.testAsync('a', 'b')
27  ).rejects.toThrowErrorMatchingSnapshot();
28});
29
30it(`defines event listener methods on native modules`, () => {
31  expect(typeof NativeModulesProxy.ExpoTest.addListener).toBe('function');
32  expect(typeof NativeModulesProxy.ExpoTest.removeListeners).toBe('function');
33});
34