kea icon indicating copy to clipboard operation
kea copied to clipboard

How to test `propsChanged` ?

Open paolodamico opened this issue 3 years ago • 1 comments

Would be great if we could document how to properly test the effects of propsChanged.

Conceptual example (code does not work like this):

let logic = myLogic({
    foo: 'bar',
})
logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({ isFooBar: true })

logic = myLogic({
    foo: 'baz',
})
await expectLogic(logic).toFinishAllListeners().toMatchValues({ isFooBar: false })

paolodamico avatar Aug 01 '22 08:08 paolodamico

Hey @paolodamico, I made a test like this... and it passes. 🤔

What could be happening in your case could perhaps be:

  • you matched some actions earlier, and now the values are stuck at the state right after the action. Try .clearHistory()
  • there is a 0ms timeout before propsChanged is triggered. Perhaps that's not enough? Try a .delay(1), or then waiting for the @KEA/FLUSH action that gets triggered after props change

Can you help tweak the test case until it fails?

Apologies for the lag in the response 😅 ... how are things? :D

mariusandra avatar Sep 18 '22 20:09 mariusandra