不确定在哪里查找此错误。
使用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 test 的结果是:
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
时忽略抛出此错误?
xml
标签,只包含以下的svg
标签。 - Agney