使用Jest运行文件时遇到意外令牌

时间:2019-07-31 14:22:23

标签: reactjs react-redux jestjs enzyme

enter image description here纱线测试 纱线运行v1.17.3 开玩笑  通过src / App.test.js   ●控制台

console.error node_modules/redux/lib/redux.js:313
  The previous state received by the reducer has unexpected type of "Array". Expected argument to be an object with the following keys: "posts"
console.error node_modules/redux/lib/redux.js:313
  The previous state received by the reducer has unexpected type of "Array". Expected argument to be an object with the following keys: "posts"
console.error node_modules/redux/lib/redux.js:313
  The previous state received by the reducer has unexpected type of "Array". Expected argument to be an object with the following keys: "posts"
console.error node_modules/redux/lib/redux.js:313
  The previous state received by the reducer has unexpected type of "Array". Expected argument to be an object with the following keys: "posts"

FAIL src / page / Search.test.js   ●测试套件无法运行

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html

Details:

SyntaxError: E:\React\data\Code\src\page\Search.js: Unexpected token (231:6)

  229 |   render() {
  230 |     return (
> 231 |       <div className="App">
      |       ^
  232 |         {/* all comtent */}
  233 | 
  234 |         <div className="container-fluid">

  at Parser.raise (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:6325:17)
  at Parser.unexpected (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:7642:16)
  at Parser.parseExprAtom (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8841:20)
  at Parser.parseExprSubscripts (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8412:23)
  at Parser.parseMaybeUnary (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8392:21)
  at Parser.parseExprOps (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8267:23)
  at Parser.parseMaybeConditional (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8240:23)
  at Parser.parseMaybeAssign (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8187:21)
  at Parser.parseParenAndDistinguishExpression (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8978:28)
  at Parser.parseExprAtom (E:\React../../../../data/Code/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8762:21)

测试套件:1个失败,1个通过,总共2个 测试:3次通过,共3次 快照:共0个 时间:3.534秒 运行所有测试套件。 错误命令失败,退出代码为1。 信息请访问https://yarnpkg.com/en/docs/cli/run,以获取有关此命令的文档。

0 个答案:

没有答案