小编Ale*_*jac的帖子

TypeError:无法读取未定义的属性“viewManagersNames” - Integrating Jest and Enzyme with React Native TypeScript Package

我正在尝试将 Jest 单元测试与 React-Native Typescript 包上的 Enzyme 集成,但在阅读文档和教程后,我似乎无法使其工作。

该问题仅在使用LinearGradientfrom时发生expo-linear-gradient
配置文件设置后(见下文),运行npm test会引发错误:

TypeError: Cannot read property 'viewManagersNames' of undefined at 
requireNativeViewManager (node_modules/@unimodules/react-native- 
adapter/src/NativeViewManagerAdapter.tsx:26:10) at Object.<anonymous> 
(node_modules/expo-linear-gradient/src/NativeLinearGradient.ios.tsx:20:59) 
at Object.<anonymous> (node_modules/expo-linear- 
gradient/src/LinearGradient.tsx:5:34).
Run Code Online (Sandbox Code Playgroud)

我尝试链接 @unimodules/react-native-adapter,因为它似乎是导致问题的原因,但随后出现错误:

SyntaxError: Unexpected token {

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
  at Object.<anonymous> (node_modules/@unimodules/core/src/AdapterProxy.ts:1:50)
Run Code Online (Sandbox Code Playgroud)

包.json

{
   ...
  "scripts": {
    "build": "tsc",
    "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
    "lint": "tslint -p tsconfig.json",
    "test": "jest --config jest.config.json --detectOpenHandles",
    "prepare": "npm run build",
    "prepublishOnly": "npm test …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs react-native enzyme expo

5
推荐指数
1
解决办法
1528
查看次数

标签 统计

enzyme ×1

expo ×1

jestjs ×1

react-native ×1

typescript ×1