【发布时间】:2018-03-29 05:04:09
【问题描述】:
不确定在哪里查找此错误。
使用 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 时忽略抛出这个错误?
【问题讨论】:
-
尝试删除
xml标签,只包含svg标签
标签: reactjs typescript jestjs