redux-logic icon indicating copy to clipboard operation
redux-logic copied to clipboard

Test failing since v2.0.0

Open bbthorntz opened this issue 6 years ago • 5 comments

Since updating to version 2.0.0 we have some failing tests. I have produced a reduced example below:

import configureStore from "redux-mock-store";
import { createLogicMiddleware, createLogic } from "redux-logic";

const ACTION_LOGOUT = "LOGOUT";
const ACTION_DO_SOMETHING = "DO_SOMETHING";

const logoutLogic = createLogic({
  type: ACTION_LOGOUT,
  latest: true,
  process: (deps, dispatch, done) => {
    dispatch({ type: ACTION_DO_SOMETHING });
    done();
  }
});

const initialState = {};
const mockStore = configureStore([createLogicMiddleware([logoutLogic])]);

describe("logoutLogic", () => {
  it("should dispatch expected actions", () => {
    const store = mockStore(initialState);
    store.dispatch({ type: ACTION_LOGOUT });
    expect(store.getActions()).toEqual([
      { type: ACTION_LOGOUT },
      { type: ACTION_DO_SOMETHING }
    ]);
  });
});

You can see the failing test in a Code Sandbox here: https://codesandbox.io/s/949yypmly4

I'm assuming that this is probably not an issue when using redux-logic-test (I haven't tried yet) but it's weird nonetheless that it only fails since [email protected].

If this is expected behaviour following the update please close the issue.

bbthorntz avatar Oct 03 '18 02:10 bbthorntz

Just a follow-up to say I re-wrote this with redux-logic-test and it works as expected. However, redux-logic-test has the following peer dependency warnings:

warning " > [email protected]" has incorrect peer dependency "redux@^3.5.2".
warning " > [email protected]" has incorrect peer dependency "redux-logic@^0.11.8 || ^0.12.0".

Working test code:

import { createMockStore } from 'redux-logic-test';
import { createLogic } from "redux-logic";

const ACTION_LOGOUT = "LOGOUT";
const ACTION_DO_SOMETHING = "DO_SOMETHING";

const logoutLogic = createLogic({
  type: ACTION_LOGOUT,
  latest: true,
  process: (deps, dispatch, done) => {
    dispatch({ type: ACTION_DO_SOMETHING });
    done();
  }
});

const initialState = {};

describe("logoutLogic", () => {
  it("should dispatch expected actions", (done) => {
    const store = createMockStore({ initialState, logic: [logoutLogic] });
    store.dispatch({ type: ACTION_LOGOUT });
    store.whenComplete(() => {
      expect(store.actions).toEqual([
        { type: ACTION_LOGOUT },
        { type: ACTION_DO_SOMETHING }
      ]);

      done();
    });

  });
});

https://codesandbox.io/s/8zojrk0w59

bbthorntz avatar Oct 03 '18 04:10 bbthorntz

@bbthorntz Thanks, that reminds me that I need to update redux-logic-test's peer deps so they are broader. I'm guessing that in the original test, one would have to wait slightly longer for all the actions to be delivered (like we do when using whenComplete).

I have updated redux-logic-test@2 to allow a broader range of redux and redux-logic.

jeffbski avatar Oct 03 '18 12:10 jeffbski

@bbthorntz I've updated your original test with redux-mock-store to have it wait for actions to complete. See it here https://codesandbox.io/s/olplx0l4vy

jeffbski avatar Oct 03 '18 23:10 jeffbski

@jeffbski thanks! Other than being slightly more terse, is there any benefit to using redux-logic-test vs. redux-mock-store?

bbthorntz avatar Oct 04 '18 01:10 bbthorntz

I hadn't seen it before, but it looks to be pretty comparable. You should be fine to use either.

jeffbski avatar Oct 07 '18 14:10 jeffbski