使用Jest间谍测试事件时的流程分开

时间:2018-07-14 23:25:38

标签: jestjs

我正在为使用process中的事件的代码运行一些Jest测试。即使我使用--runInBand运行Jest,我的测试中的“重叠”事件还是有问题。

test('My Test',  () => {

  // some code that calls the "something" event once
  ...
})

test('Another Test',  () => {
  const spy = jest.fn()
  process.on('something', spy)
  // some code that calls the "something" event once
  ...
  expect(spy).toHaveBeenCalledTimes(1)
})

如果我当时使用test.only进行了一项测试,则测试通过。但是,当我全部运行它们时-无论有无--runInBand,第二个都无法说我的间谍被叫了两次。我该如何解决这个问题?

0 个答案:

没有答案