开玩笑测试在create-react-native-app项目中的第一个导入语句(意外标识符)失败

时间:2018-10-19 05:28:48

标签: jestjs create-react-native-app

尝试使用笑话并尝试在现有create-react-native-app上运行的现有npm test项目上立即遇到测试失败,即使该代码在android studio AVD中运行时看起来也可以正常工作。问题中的错误看起来像

➜ npm test

> spicex_react_native@0.1.0 test /path/to/project
> jest

 PASS  __tests__/example-test.js
 FAIL  ./App.test.js
  ● Test suite failed to run

    /home/me/path/to/project/node_modules/tcomb-form-native/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import t from "./lib";
                                                                                                    ^

    SyntaxError: Unexpected identifier

    > 1 | import { PropTypes } from 'prop-types';
      2 | import React from 'react';
      3 | import { Alert, Button, ScrollView, StyleSheet, Text, View } from 'react-native';
      4 | import Spinner from 'react-native-loading-spinner-overlay';

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
      at Object.<anonymous> (app/containers/path/to/some/component.js:1:1290)

Test Suites: 1 failed

检查android AVD中由component.js文件表示的组件,屏幕呈现时没有任何错误或警告。项目的package.json看起来像

{
  "name": "spicex_react_native",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "eslint": "^5.3.0",
    "eslint-config-standard": "^11.0.0",
    "eslint-plugin-import": "^2.13.0",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-react": "^7.10.0",
    "eslint-plugin-react-redux": "^2.3.0",
    "eslint-plugin-standard": "^3.1.0",
    "jest-expo": "~27.0.0",
    "react-native-scripts": "^1.14.1",
    "react-test-renderer": "16.3.1"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo"
  },

不能完全确定如何仅从文档(https://jestjs.io/docs/en/tutorial-react-native.html#setup)中进行调试。如果有人知道这里会发生什么,将不胜感激。

0 个答案:

没有答案