0

I am trying to do a Snapshot test in React Native for Android, but I am running into an error:

As soon as I include Dimensions into my setupFiles I get this error.
@react-native-firebase/app is included in transformIgnorePatterns. How can I fix this or mock this?

 import { Platform } from 'react-native';
    ^^^^^^

 SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/@react-native-firebase/auth/lib/index.js:18:1)


react-native mock file.

import * as ReactNative from "react-native";

export const Dimensions = {
    get: (param) => {
        //if (param === "window") {
        return {
            width: 414,
            height: 818
        };
        //}
    }
};
export const StyleSheet = {
    create: () => ({})
};
export const Platform = {
    ...ReactNative.Platform,
    OS: "android",
    Version: 123,
    isTesting: true,
    select: objs => objs[Platform.OS]
};

export default Object.setPrototypeOf(
    {
        Platform,
        StyleSheet,
        Dimensions
    },
    ReactNative
);

Tried various mock setups. Removed @react-native-firebase/app from transformIgnorePatterns. Totally lost at the moment on which path to take next.

0 Answers0