我正在进行一次史诗测试。问题?我用延迟。见
export const displayToasterEpic = (action$, store) =>
action$
.ofType(SHOW_TOASTER)
.filter(action => action.toaster.show)
.delay(getToaster(store.getState()).duration || DELAY_TOASTER)
.map(() => showToaster(MESSAGE_CLOSE));
我的测试:
describe('displayToasterEpic', () => {
it('should display toaster delete account', () => {
const expectedAction1 = {
type: SHOW_TOASTER,
toaster: MESSAGE_DELETE_ACCOUNT,
};
const expectedAction2 = {
type: SHOW_TOASTER,
toaster: MESSAGE_CLOSE,
};
store = mockStore(displayToasterEpic);
store.dispatch(expectedAction1);
expect(store.getActions()).toEqual([expectedAction1, expectedAction2]);
});
问题是这种延迟。 jest.clearAllTimers();
有什么想法吗?
答案 0 :(得分:0)
我发现自己是模拟延迟的漂亮解决方案。使用方法spyOn:)