Last active
September 22, 2017 16:20
-
-
Save brunoguerra/0e4beb35ddc2160a5c0b60718746d445 to your computer and use it in GitHub Desktop.
Jest - Testing Redux with Mocking Store and Factory
This file contains hidden or 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 'prop-types' | |
import GridFactory, { GridContainerFactory } from '../GridContainer' | |
import { mount } from 'enzyme' | |
const mockRequestAction = { type: 'REQUEST_ACTION_TEST' } | |
const List = ({ records }) => <ul records={records}></ul> | |
const props = { | |
addFormUniqueName: 'form1', | |
reducerName: 'form-test-x', | |
requestAction: () => mockRequestAction, | |
createRequestAction: () => ({}), | |
updateRequestAction: () => ({}), | |
removeRequestAction: () => ({}), | |
List, | |
} | |
const data = ['ListOfThings'] | |
const store = { | |
getState: () => ({ [props.reducerName]: data }), | |
dispatch: jest.fn(), | |
subscribe: jest.fn(), | |
} | |
const ConnectedComponent = GridFactory(props) | |
describe('GridContainer', () => { | |
it('renders without crash', () => { | |
const wrapper = mount(<ConnectedComponent store={store} />) | |
const list = wrapper.find('ul') | |
expect(list.length).toBe(1) | |
expect(list.props().records).toBe(data) | |
expect(store.dispatch.mock.calls.length).toBe(1) | |
expect(store.dispatch.mock.calls[0][0].type).toBe(mockRequestAction.type) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment