Skip to content

Add "withMiddlewares" to allow override middlewares per test #23

Open
@dmitry-zaets

Description

@dmitry-zaets

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions