Jest有模拟假冒时间旅行的方法,要在您的情况下使用它,我想您可以按照以下样式更改代码:
import { API } from 'api';import { API as mockAPI } from '__mocks/api';API.get = jest.fn().mockImplementation(mockAPI.get);jest.useFakeTimers(); // this statement makes sure you use fake timersdescribe('Something Component', () => { it('renders after data loads', () => { const wrapper = mount(<Something />); // skip forward to a certain time jest.runTimersToTime(1); expect(mountToJson(wrapper)).toMatchSnapshot(); });});
另外,
jest.runTimersToTime()您也可以使用
jest.runAllTimers()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)