【发布时间】:2019-07-27 12:53:03
【问题描述】:
我使用 Jest 编写了一个集成测试:
import 'jest-styled-components';
import React from 'react';
import { remAuto } from 'tidee-life-theme';
test('blah', () => {});
我得到了这个奇怪的输出:
Cannot find module 'react-hot-loader' from 'core.js'
7 | const core = {
8 | 'background-color': '#fff',
> 9 | 'color': fontColor,
| ^
10 | 'font-family': fontFamily,
11 | 'font-family-bold': fontFamilyBold,
12 | 'font-size': fontSize,
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
at ../tidee-life-theme/src/core.js:9:91
at Object.<anonymous> (../tidee-life-theme/src/core.js:11:3)
当我查看core.js时,并没有提到react-hot-loader:
export const fontColor = "#666";
export const fontFamily = `'open_sansregular', helvetica, arial`;
export const fontFamilyBold = `'open_sansbold', helvetica, arial`;
export const fontSize = 13;
export const fontLineHeight = 17 /13;
const core = {
'background-color': '#fff',
'color': fontColor,
'font-family': fontFamily,
'font-family-bold': fontFamilyBold,
'font-size': fontSize,
'line-height': fontLineHeight,
};
export default core;
我正在使用 lerna,tidee-life-theme 位于与正在运行测试的包相邻的包中。
那么,这里到底发生了什么?
【问题讨论】:
-
您是否将热重载包装的组件导入到您的测试中?
-
不,我不是。我还没有开始导入任何组件。我正在导入的
utils.js文件仅包含样式组件的辅助函数。 -
检查 core.js 中的特殊字符。您的问题是一个真正的谜。
-
感谢您的建议,但我检查了,没有特殊字符。