【发布时间】:2017-07-11 14:13:12
【问题描述】:
我正在尝试将具有热模块重新加载设置的模块的覆盖率提高到 100%。
在我的模块中,我有这个:
// app.js
if (module && module.hot) module.hot.accept();
在测试文件中我正在尝试这样做
// app.test.js
it('should only call module.hot.accept() if hot is defined', () => {
const accept = jest.fn();
global.module = { hot: { accept } };
jest.resetModules();
require('./app');
expect(accept).toHaveBeenCalled();
}
);
但是当我在 app.js 中注销模块时,它会显示需要的东西,但不包含测试设置的热方法。
【问题讨论】:
-
我也没有找到答案,但这似乎是可以接受的: /* istanbul ignore if */ 就在 if (module && module.hot... 行
标签: javascript reactjs jestjs