0

我正在尝试为 React Native 应用程序执行单元测试和集成测试。由于 tcomb-form-native 库,运行yarn test --coverage我的几个测试套件时无法运行。

我收到此特定错误:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import t from "./lib";

SyntaxError: Unexpected identifier

  13 | // import { gray } from 'ansi-colors';
  14 |
> 15 | import t from 'tcomb-form-native';
     | ^
  16 |
  17 | const Form = t.form.Form;
  18 |

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
  at Object.<anonymous> (screens/ReservationScreen.js:15:1)

package.json我在库的 GitHub 的测试部分之后更新了文件, https://github.com/gcanti/tcomb-form-native,但继续收到相同的错误。

我对 tcomb-form-native 自述文件测试描述中的这一行感到困惑:

  "ios.js"    <<<<<<<<<<<< this needs to be defined!

我使用 Expo 创建了 React Native 应用程序,所以我没有 ios.js 文件。与 GitHub 中的示例代码唯一的区别"jest":是我也"preset": "jest-expo",定义了。

package.json为了让我的测试套件运行,我需要对我的文件或测试套件进行哪些更改?(他们不必通过,只需运行即可。)


编辑:

我尝试package.json根据https://github.com/gcanti/tcomb-form-native/issues/443的最佳答案添加以下代码:

"transformIgnorePatterns": [
  "node_modules/(?!react-native|tcomb-form-native)"
]`

我从库的 GitHub 自述文件中添加了没有原始建议编辑的代码,并将其添加到建议的编辑中。SyntaxError: Unexpected identifier当我运行测试时,我仍然收到。


编辑#2:

我改成import t from 'tcomb-form-native';var t = require('tcomb-form-native');,我仍然收到SyntaxError: Unexpected identifier.

4

0 回答 0