Skip to content

Instantly share code, notes, and snippets.

@paulsturgess
Last active April 6, 2017 20:03
Show Gist options
  • Save paulsturgess/e0f06a12821343d7854718c34394b60e to your computer and use it in GitHub Desktop.
Save paulsturgess/e0f06a12821343d7854718c34394b60e to your computer and use it in GitHub Desktop.
Test redux container component
import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
import actions from '../actions'
import ConnectedAddTodo from './AddTodo.js'
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
const store = configureMockStore()({});
describe('AddTodo', () => {
let instance, container;
beforeEach(() => {
spyOn(store, 'dispatch')
instance = TestUtils.renderIntoDocument(
<Provider store={store}>
<ConnectedAddTodo />
</Provider>
);
});
it('sets the addTodo prop on the AddTodoForm Component', () => {
container = TestUtils.findRenderedComponentWithType(instance, ConnectedAddTodo)
let action = container.renderedElement.props.addTodo('test')
expect(store.dispatch).toHaveBeenCalledWith(
{ type: 'ADD_TODO', id: 0, text: 'test' }
);
});
});
@mealeyst
Copy link

mealeyst commented Apr 6, 2017

So I tried this example using the shallow render method of enzyme and sinon.js to spy my dispatch method. While checking to see if dispatch was called passes, trying to check the arguments that dispatch is called with however doesn't yield the results that I am expecting. Doing console.logs in the actions creators does however show that they appear to be firing.

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