【发布时间】:2020-02-05 13:39:12
【问题描述】:
我尝试为大多数测试模拟一些节点模块,根据doc 我将模拟文件放入 __mocks__ 文件夹,但我也想在特定测试中使用真实模块,我试过开玩笑。 unmock('some-module') 但不工作。
这是我的项目结构:
├──__mocks__
│ └── foo.js
│──doSomething.js
│──test.js
__mocks__/foo.js
const foo = jest.genMockFromModule('foo');
module.exports = foo;
doSomething.js
const foo = require('foo');
const doSomething = () => {
foo.bar();
};
module.exports = doSomething;
test.js
const doSomething = require('./doSomething');
describe('Test', () => {
it('doSomething() should call foo.bar', () => {
doSomething();
expect(foo.bar).toBeCalled();
})
it('use real foo module', () => {
// How could I use real foo module in this test?
jest.unmock('some-module'); // not working
doSomething();
})
})
【问题讨论】:
标签: jestjs