Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failing since v2.0.0 #126

Open
bbthorntz opened this issue Oct 3, 2018 · 5 comments
Open

Test failing since v2.0.0 #126

bbthorntz opened this issue Oct 3, 2018 · 5 comments

Comments

@bbthorntz
Copy link

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
Copy link
Author

bbthorntz commented Oct 3, 2018

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

@jeffbski
Copy link
Owner

jeffbski commented Oct 3, 2018

@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
Copy link
Owner

jeffbski commented Oct 3, 2018

@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

@bbthorntz
Copy link
Author

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

@jeffbski
Copy link
Owner

jeffbski commented Oct 7, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants