即使禁用自动模拟,开玩笑自动模拟是否缺少依赖项?

Does jest auto mock missing dependencies even when auto mocking is disabled?

I wrote a decorator simplify smart/dumb components separation in ReactJS, at one point I tried to break the test code into multiple files and moved the colaborator classes to the __mocks__ directory.

文件结构变为:

src
  __mocks__
    SharedComponent.js
    SomeComponent.js
    SomePresenter.js
    SpecificPresenter.js
  __tests__
    index.js
  index.js 

在测试文件 index.js 中加载 SomeComponent 我这样做:

import SomeComponent from 'SomeComponent'

那个class只存在于mocks目录下,它只是用来测试装饰器的。 You can see here that I am not mocking that class explicitly and in the manual says that auto mocking is disabled by default.

即使禁用自动模拟,jest auto mock 是否缺少依赖项?

Thanks to Michał Pierzchała in this comment:

When a manual mock exists for a given module, Jest's module system will use that module when explicitly calling jest.mock('moduleName'). However, manual mocks will take precedence over node modules even if jest.mock('moduleName') is not called. To opt out of this behavior you will need to explicitly call jest.unmock('moduleName') in tests that should use the actual module implementation.