New to using jest and running into immediate test failure on an existing create-react-native-app
project when trying to run npm test
even though the code appears to work fine when run in the android studio AVD. Error in question looks like
➜ 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
Examining the component denoted by the component.js file in the android AVD, the screen renders without any errors or warnings. And the project's package.json looks like
{
"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"
},
Was not totally sure how could debug properly from just the docs (https://jestjs.io/docs/en/tutorial-react-native.html#setup). If anyone knows what could be going on here, advice or suggestions would be appreciated.