redux-things/redux-actions-assertions

Add "withMiddlewares" to allow override middlewares per test

dmitry-zaets opened this issue · 0 comments

Redux Thunk 2.1.0 adds the possibility to register dependencies of async action in middleware setup (reduxjs/redux#1716), which is useful for testing.

Currently, there is a way to set middlewares for all tests during initial setup, so there is no need to set up middlewares for each test.

registerMiddlewares([ thunk ]);
registerInitialStoreState(buildInitialStoreState(rootReducer));

But there is also no way to override middlewares for separate tests.

We can add method withMiddlewares to test methods chain, that will allow overriding existing middlewares for a single test.

Usage (with expect):

const result = Promise.resolve({id:1234});
const api = { get: expect.createSpy().andReturn(result) };

expect(actionA()).withMiddlewares(thunk.withExtraArgument({ api })).toDispatch([
  { type: action_a_start },
  { type: action_a_success },
  actionB()
], done);