如何在react-native中使用排毒功能进行模拟

xxls0lw8  于 2022-11-17  发布在  React
关注(0)|答案(1)|浏览(124)

如何在react-native中使用detox来模拟函数。我正在使用谷歌登录应用程序,想模拟谷歌登录的函数,尝试了jest和@testinglibrary,但我无法通过getText/getTestID为选择器或其他组件获取元素。有很多关于react-native中测试的事情,但我无法找到正确的方法来做。如何测试一个React原生应用程序,我使用谷歌登录,每个页面都从AWS数据库获取用户的详细信息,并显示修改的详细信息。
目前我正在使用以下库

"@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"
    ]
  }
ars1skjm

ars1skjm1#

看一看mocking guide for Detox
请注意,您不能使用以前的笑话经验中熟悉的嘲弄技巧,即使排毒在笑话之上运行,例如:

jest.mock('./src/myModule');  // NO, THIS WON'T WORK

所有的嘲笑必须进行的帮助下,地铁捆绑,其中权力的React原住民引擎盖下。

相关问题