我使用Next.js创建Web应用程序,并使用Jest进行单元测试。我使用带有jest(https://github.com/zeit/next.js/tree/master/examples/with-jest)的create-next-app中的模板设置了项目。一切正常,直到我使用style-jsx添加样式为止。运行jest --coverage
时出现此错误。
TypeError: Property body[1] of BlockStatement expected node to be of a type ["Statement"] but instead got "SequenceExpression"
at validate (node_modules/@babel/types/lib/definitions/utils.js:128:13)
at validator (node_modules/@babel/types/lib/definitions/utils.js:97:7)
at Object.validate (node_modules/@babel/types/lib/definitions/utils.js:172:7)
at validate (node_modules/@babel/types/lib/validators/validate.js:17:9)
at builder (node_modules/@babel/types/lib/builders/builder.js:46:27)
at Object.BlockStatement (node_modules/@babel/types/lib/builders/generated/index.js:260:31)
at NodePath.replaceExpressionWithStatements (node_modules/@babel/traverse/lib/path/replacement.js:209:57)
at NodePath.insertBefore (node_modules/@babel/traverse/lib/path/modification.js:49:17)
at processTaggedTemplateExpression (node_modules/next/node_modules/styled-jsx/dist/babel-external.js:97:16)
at node_modules/next/node_modules/styled-jsx/dist/babel-external.js:183:11
当我仅在没有覆盖范围的情况下运行jest
时,测试通过了。
我在https://github.com/zeit/styled-jsx/issues/436处读过相同的问题。但是,问题仍然存在,没有人找到答案。