首页 > 解决方案 > 反应笑话测试中意外令牌导入错误

问题描述

我的 jest.config.js文件包含下面给出的数据。

但是当我运行测试命令时,它给了我 SyntaxError 错误:

意外的令牌导入

当我触发测试命令时出现错误

e

const path = require('path');

module.exports = {
bail: true,
rootDir: process.cwd(),
testRegex: '/__tests__/.*\\.test\\.jsx?$',
transform: { '/__tests__/.*': path.resolve(__dirname, 'jest.transform.js'),},
verbose: true,
};

标签: reactjsjestjsbabel-jest

解决方案


请安装"babel-jest": "^23.0.1",并添加以下转换配置:

const path = require('path');
module.exports = {
bail: true,
rootDir: process.cwd(),
testRegex: '/__tests__/.*\\.test\\.jsx?$',
"transform": {
  "\\.js$": "<rootDir>/node_modules/babel-jest"
},
verbose: true,
};

让我知道问题是否仍然存在


推荐阅读