运行快照测试时失败。
在我正在测试的组件下面。
function Footer() {
const windowWidth = useWindowSize().windowWidth;
return (
<footer
style={{
minWidth: windowWidth,
}}
>
Made by XXX
</footer>
);
}
export default Footer;
这是我写的测试
describe('Footer', () => {
it('renders as expected', () =>{
const tree = TestRenderer.create(<FooterView/>).toJSON();
console.log(tree);
});
});
这是我收到的错误。
Test suite failed to run
SyntaxError: D:\MyProGit\frontend\src\__tests__\Footer.test.js: Unexpected token (8:37) at Parser.raise (C:/Users/user/AppData/Roaming/npm/node_modules/jest-cli/node_modules/@babel/parser/src/parser/location.js:41:63)
我执行了教程Testing React Apps中给出的相同步骤,但是最后,我找不到文件babel.config.js
。
{
"devDependencies": {
"@babel/preset-env": "^7.8.4",
"@babel/preset-react": "^7.8.3",
"babel-jest": "^24.9.0",
"jest": "^24.9.0",
"react-test-renderer": "16.12.0"
}
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject"
},
}