2017-06-30 40 views
0

我正在進行史詩測試。問題?我使用延遲。見模擬延遲的可能性?

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]); 
    }); 

的probleme是這種延遲。同樣的問題,當jest.clearAllTimers();

enter image description here

任何想法?

+0

當你使用'jest.useFakeTimers()'''時使用'jest.runAllTimers();' –

回答

0

我發現自己是模擬延遲的一個很好的解決方案。使用方法spyOn :)