0

我已经看到使用类似这样的语法来模拟依赖项的单元测试:

    const FirstMenuItem = () => <div />;
    const SecondMenuItem = () => <div />;
    const ThirdMenuItem = () => <div />;

    beforeEach(() => {
        __RewireAPI__.__Rewire__('FirstMenuItem', FirstMenuItemMock);
        __RewireAPI__.__Rewire__('SecondMenuItem', SecondMenuItemMock);
        __RewireAPI__.__Rewire__('ThirdMenuItem', ThirdMenuItemMock);
    });
    
    afterEach(() => {
        __RewireAPI__.__ResetDependency__('FirstMenuItem');
        __RewireAPI__.__ResetDependency__('SecondMenuItem');
        __RewireAPI__.__ResetDependency__('ThirdMenuItem');
    });

但我也看到jest.mock提到不少。我想知道,对于上述 Rewire 语句,jest.mock等价物是什么?如果您有任何有用的文档也将不胜感激!(我很难找到有关 Rewire 的文档,因此很难理解这会是什么样子使用jest.mock......)

4

0 回答 0