redux-actions-assertions icon indicating copy to clipboard operation
redux-actions-assertions copied to clipboard

How to chain multiple expectations

Open pandaiolo opened this issue 5 years ago • 1 comments

Sorry if the issues are not the correct place to ask a question!

I'd like to assert that an action is causing some other actions to trigger, but not others.

For example, doStuff() should trigger fooHappened() but not barDidNot()

Example code that I would like to build:

it('does stuff as expected', async done => {
  expect(doStuff())
    .toDispatchActions([fooHappened()], done)
    .toNotDispatchActions([barDidNot()], done)
})

Two things seem problematic above:

  1. Chaining the expectations? (I think not)
  2. Async management: calling done two times is probably going to break?

Currently, I'm making two different tests to assert for the same action, one to check what triggers as expected, one to check what is not triggered as expected

Is this the right way to do it?

Thanks for the hints.

pandaiolo avatar Nov 23 '20 15:11 pandaiolo

Hi, unfortunately with the current implementation it is not possible to chain the assertions, but I think you can just do two asserts one by one, something like this (not sure about using the awaits though):

it('does stuff as expected', async () => {
  const action = await doStuff()
  await expect(action).toDispatchActions([fooHappened()])
  await expect(action).toNotDispatchActions([barDidNot()])
})

dmitry-zaets avatar Nov 30 '20 14:11 dmitry-zaets