我目前正在尝试将Jest纳入我的本机项目中。
但是,在开玩笑时遇到错误SyntaxError: Unexpected token {
。
这是package.json:
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/runtime": "^7.6.3",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.6.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.3",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native",
"cacheDirectory": "./cache",
"coveragePathIgnorePatterns": [
"./app/utils/vendor"
],
"coverageThreshold": {
"global": {
"statements": 80
}
},
"transformIgnorePatterns": [
"/node_modules/(?!react-native|react-clone-referenced-element|react-navigation|native-base-shoutem-theme|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
]
}
这是我的App-test.js文件:
import React from 'react';
import renderer from 'react-test-renderer';
import SomeComponent from '../components/Map';
jest.mock('react-native-google-signin', () => {
return {
statusCodes: {
SIGN_IN_CANCELLED: '',
IN_PROGRESS: '',
PLAY_SERVICES_NOT_AVAILABLE: '',
},
};
});
describe('Some component', () => {
it('renders correctly', () => {
const tree = renderer.create(<SomeComponent />).toJSON();
expect(tree).toMatchSnapshot();
});
});
该错误显示在我要测试的任何文件上。 有关如何解决此问题的任何想法?