Last active
November 24, 2017 11:20
-
-
Save ndelitski/99915eac185cbd8ee1b2cdb8031ced4e to your computer and use it in GitHub Desktop.
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 { 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