Jestjs jest mock:如何在特定测试中使用真实模块?

Jestjs jest mock:如何在特定测试中使用真实模块?,jestjs,Jestjs,我尝试为大多数测试模拟一些节点模块,根据我将模拟文件放入_umock__;文件夹,但我也想在特定测试中使用真实模块,我尝试了jest.unmack('some-module'),但不起作用 这是我的项目结构: ├──__mocks__ │   └── foo.js │──doSomething.js │──test.js __mocks__u/foo.js const foo = jest.genMockFromModule('foo'); module.exports = foo; doS

我尝试为大多数测试模拟一些节点模块,根据我将模拟文件放入_umock__;文件夹,但我也想在特定测试中使用真实模块,我尝试了jest.unmack('some-module'),但不起作用

这是我的项目结构:

├──__mocks__
│   └── foo.js
│──doSomething.js
│──test.js
__mocks__u/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();
  })

})

您可以使用
requireActual
绕过模拟模块:

const doSomething = jest.requireActual('some-module');
doSomething();
文件: