2015-04-20 182 views
2

我想弄清楚如何用Jasmine測試Reflux商店(https://github.com/spoike/refluxjs)。基本上,這個問題相當於,除了一個事實,即沒有相當於runAllTimes我所知道的:How to test Reflux actions with Jest用茉莉花測試Reflux商店

it('responds to the doTheThing action and triggers afterward', function() { 
    var spyFn = jasmine.createSpy('spy'); 
    MyStore.listen(spyFn); 
    MyActions.doTheThing(); 
    // with Jest, I would call jest.runAllTimers() here 
    expect(spyFn).toHaveBeenCalled(); 
}); 

^失敗,當它應返回true。

因此:任何人都知道如何使用茉莉花測試迴流店?

回答

1

我通過手動滴答茉莉花時鐘解決了這個問題。

jasmine.clock().tick(jasmine.DEFAULT_TIMEOUT_INTERVAL);

(隨着分別在安裝和拆卸,調用jasmine.clock().install()jasmine.clock().uninstall()

這感覺就像一個黑客攻擊。任何人都有更好的方法?