使用Jasmine测试Reflux商店

时间:2015-04-20 20:53:27

标签: jasmine reactjs refluxjs

我正试图弄清楚如何使用Jasmine测试Reflux商店(https://github.com/spoike/refluxjs)。基本上,相当于这个问题,除了我所知道的runAllTimes没有等同的事实:How to test Reflux actions with Jest

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。

那么:有谁知道如何使用Jasmine测试Reflux商店?

1 个答案:

答案 0 :(得分:1)

我通过手动勾选Jasmine时钟解决了这个问题。

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

(分别在设置和拆解时调用jasmine.clock().install()jasmine.clock().uninstall()。)

这感觉就像一个黑客。谁有更好的方法?

相关问题