微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Jest 在 React 测试中遇到了一个意外的标记

如何解决Jest 在 React 测试中遇到了一个意外的标记

我的测试用例文件之一出错。我收到此行的错误

import cv2
im = cv2.imread('lines.png',cv2.IMREAD_GRAYSCALE)

# Count objects - initially 2
nObjects = len(cv2.findContours(im,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[0])

# Draw white line connecting white px 1 and white px 2
cv2.line(im,(w1x,w1y),(w2x,w2y),255,1)

# Count objects - still 2
nObjects = len(cv2.findContours(im,cv2.CHAIN_APPROX_SIMPLE)[0])

# Draw white line connecting white px 1 and white px 3
cv2.line(im,(w3x,w3y),1)

# Count objects - Now just 1
nObjects = len(cv2.findContours(im,cv2.CHAIN_APPROX_SIMPLE)[0])

由于某种原因,它收到如下错误

import { ReactComponent as bestSeller } from "../../collection/images/icons/hello.svg";

我在 ● Test suite Failed to run 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: • If you are trying to use ECMAScript Modules,see https://jestjs.io/docs/en/ecmascript-modules for how to enable it. • 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: C:\*********collections\images\icons\hello.svg:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path class="a" d="M1667.949,842.606,1657,853.559l.048,5,.049L1673,847.653Zm3.028,5.047-.478.478-3.028-3.028.478-.478Zm-9.521,9.52-3-.029-.029-3,8.033-8.033,1.01,1.01-7.741,7.74,1.009,7.741-7.74,1.009Z" transform="translate(-1656.996 -842.606)"/></svg> ^ SyntaxError: Unexpected token '<' 中的 Jest 配置如下所示:

package.json

使用“babel-jest”:“24.7.1” 和

"jest": {
    "verbose": true,"snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],"setupFiles": [
      "<rootDir>/src/setupTests.js"
    ]
  },

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。