Last active
April 6, 2017 20:03
-
-
Save paulsturgess/e0f06a12821343d7854718c34394b60e to your computer and use it in GitHub Desktop.
Test redux container component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thatdispatch
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.