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

Testing nested actions #169

Closed
kostyanet opened this issue Sep 19, 2019 · 2 comments
Closed

Testing nested actions #169

kostyanet opened this issue Sep 19, 2019 · 2 comments

Comments

@kostyanet
Copy link

kostyanet commented Sep 19, 2019

Hi @dmitry-zaets!
Could you please point out why I cannot test a nested action like below:

import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
const store = mockStore({
	stream: {}
});

const successAction = (type, data={}) => ({
  type,
  payload: {
     ...data,
    isPending: false,
  }
});

function handleOverrideSuccess(stream, overriddenValues) {
	return () => {
		const update = {
			...stream,
			...overriddenValues
		};
		return store.dispatch(successAction(
			def.STREAM_OVERRIDE_SUCCESS,
			{ stream: update }
		));
	}
}

describe('Function `handleOverrideSuccess`', () => {
    it('should dispatch actions', () => {
        const expectedAction = successAction(
	  def.STREAM_OVERRIDE_SUCCESS,
	  { stream: {} }
        );
      
        handleOverrideSuccess({}, {})();
	const acts = store.getActions();
	expect(acts[0]).toEqual(expectedAction);
  });
});
@kostyanet
Copy link
Author

kostyanet commented Sep 19, 2019

Having modified the test suite as follows doesn't help also:

it('should dispatch actions', () => {
      const spy = jest.spyOn(store, 'dispatch');
      
      handleOverrideSuccess({}, {})();
      expect(spy).toHaveBeenCalled();
});

@dmitry-zaets
Copy link
Collaborator

dmitry-zaets commented Feb 17, 2020

Take a look on https://redux-things.github.io/redux-actions-assertions/what_it_does.html and this issue for more details: #71

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

No branches or pull requests

2 participants