我已经使用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位于与运行测试的包相邻的包中。那么,到底是怎么回事呢?
发布于 2019-03-07 10:18:13
React-Hot有一个巴别塔插件,它可以将require('react-hot-loader')添加到每个文件中。所以-即使你看不到它-它可能就在那里。
解决方案-禁用jest的react-hot-loader插件(或仅为web启用)。
有不同的方法可以做到这一点。最简单的方法是通过webpack.conf中的babel-loader配置选项添加,然后从.babelrc中删除。
https://stackoverflow.com/questions/55013250
复制相似问题