Skip to content

Instantly share code, notes, and snippets.

@ndelitski
Last active November 24, 2017 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndelitski/99915eac185cbd8ee1b2cdb8031ced4e to your computer and use it in GitHub Desktop.
Save ndelitski/99915eac185cbd8ee1b2cdb8031ced4e to your computer and use it in GitHub Desktop.
import React from 'react'
import { mount } from 'enzyme'
import { createStore } from 'redux'
import { Provider as StoreProvider, connect } from 'react-redux'
test('render form text field', () => {
const changeTitle = title => ({
type: 'CHANGE_TITLE',
payload: { title },
})
const store = createStore(
(state, action) => {
switch (action.type) {
case 'CHANGE_TITLE':
return action.payload
default:
return state
}
},
{
title: 'First title',
}
)
const Button = ({ title }) =>
<div>
{title}
</div>
const ConnectedButton = connect(state => ({
title: state.title,
}))(Button)
const wrapper = mount(
<StoreProvider store={store}>
<ConnectedButton />
</StoreProvider>
)
expect(wrapper.find('Button').props().title).toEqual('First title')
store.dispatch(changeTitle('Second'))
console.log(store.getState()) // Print "Second"
expect(wrapper.update().find('Button').props().title).toEqual('Second') // Works!
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment