Search code examples
reactjsreact-nativeunit-testingjestjsreact-native-firebase

how to mock remote-config from @react-native-firebase/remote-config


I am trying to mock the remote-config module from the npm library @react-native-firebase/remote-config however, I keep getting this error back. I have attempted to mock it below but obviously, it must be incorrect I am just unsure of what is incorrect

Test suite failed to run

    TypeError: (0 , _remoteConfig.default)(...).setDefaults is not a function
jest.mock("@react-native-firebase/remote-config", () => ({
  __esModule: true,
  default: () => ({
    remoteConfig: jest.fn(() => ({
      setDefaults: jest.fn(),
    })),
  }),
}));
import remoteConfig from '@react-native-firebase/remote-config';

// set defaults
remoteConfig().setDefaults(firebaseRemoteConfig);

// fetch remote config
.
.
.

Solution

  • the correct way to write the test case for remote-config.

    jest.mock("@react-native-firebase/remote-config", () => ({
      __esModule: true,
      default: () => ({
        setDefaults: jest.fn(),
      }),
    }));