不确定在哪里查找此错误。
使用 Typescript 和 React,以及 Jest 和 Enzyme 进行单元测试。
Package.json 示例:
"scripts": {
"start": "node server.js",
"bundle": "cross-env NODE_ENV=production webpack -p",
"test": "jest"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
}
运行 npm 测试结果:
FAIL src/components/Component.test.tsx
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<?xml version="1.0" encoding="UTF-8"?>
^
SyntaxError: Unexpected token <
编辑:它似乎发生在我require
用来加载静态.svg
文件的第一个地方。为什么它不能处理?有没有办法在使用 require 时忽略抛出这个错误?