Skip to content

Testing redux modules

Diego Haz edited this page May 19, 2017 · 4 revisions

In short:

Dispatch action foo, expect state to be bar after some time, no matter what happened in the middle.

dispatch(resourceCreateRequest({ title: 'foo' }))
await delay(100)
expect(getList(getState())).toEqual([
  { title: 'foo' },
])

See src-example/store/resource/test.js

As you've seen on other topics, unit testing redux things is very easy, but that's often too much work, repetition and sometimes it's impossible to do TDD. In other words, it can be hard to write tests before writing actual code because tests are very coupled to their implementations.

In addition, many teams working on quickly evolving projects will prefer to not write unit tests because requirements and implementations change very fast.

Writing integration tests for redux modules is an alternative solution for that.

Clone this wiki locally