keajs / kea

Batteries Included State Management for React

Home Page:https://keajs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to test `propsChanged` ?

paolodamico opened this issue · 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 })

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