How to mock a function using detox in react-native

Viewed 88

How to mock functions in react-native using detox. I am using google sign in app and want to mock the function for google sign in tried jest and @testinglibrary but there I am not able to get the elements by getText/getTestID for picker or other components. There is many things about testing in react-native but I am not able to find the right way to do it. How to test a react native app where I am using google sign in and each page is fetching details about users from AWS database and displaying details for modification.

Currently i am using the following libraries

    "@react-native-async-storage/async-storage": "^1.15.5",
    "@react-native-google-signin/google-signin": "^7.0.0-alpha.3",
    "@react-native-picker/picker": "^1.16.5",
    "@react-navigation/bottom-tabs": "^6.0.4",
    "@react-navigation/drawer": "^6.1.8",
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/native-stack": "^6.0.4",
    "add": "^2.0.6",
    "react": "17.0.1",
    "react-native": "0.64.2",
    "react-native-elements": "^3.4.2",
    "react-native-file-picker": "0.0.21",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-pager-view": "^5.4.1",
    "react-native-reanimated": "^2.2.3",
    "react-native-safe-area-context": "^3.3.0",
    "react-native-screens": "^3.5.0",
    "react-native-tab-view": "^3.1.1",
    "react-native-vector-icons": "^8.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.14.8",
    "@babel/runtime": "^7.14.8",
    "@react-native-community/eslint-config": "^3.0.0",
    "@testing-library/react-native": "^8.0.0",
    "babel-jest": "^27.0.6",
    "detox": "^18.20.3",
    "eslint": "^7.31.0",
    "jest": "^27.0.6",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-test-renderer": "17.0.1"
  },
  "jest": {
    "preset": "react-native",
    "moduleNameMapper": {
      ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "babel-jest"
    },
    "transformIgnorePatterns": [
      "node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)"
    ]
  },
  "detox": {
    "configurations": {
      "android.emu.debug": {
        "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
        "build": "cd android && gradlew clean assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
        "type": "android.emulator",
        "name": "Pixel_2_API_29"
      }
    },
    "test-runner": "jest",
    "testMatch": [
      "<roots>/**/*.spec.js"
    ]
  }
0 Answers
Related