Created
June 27, 2018 14:41
-
-
Save gustavocardoso/4cdd17694f163af876fcc9e763304a75 to your computer and use it in GitHub Desktop.
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 { connect } from 'react-redux' | |
import { increment, decrement } from './actions' | |
export const Counter = ({counter, increment, decrement}) => { | |
return ( | |
<div> | |
<p className='counter'>Counter: {counter}</p> | |
<button className='increment' onClick={() => increment(10)}>+</button> | |
<button className='decrement' onClick={() => decrement(5)}>-</button> | |
</div> | |
) | |
} | |
const mapStateToProps = (state) => { | |
return { | |
counter: state.counter | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
increment: (value) => dispatch(increment(value)), | |
decrement: (value) => dispatch(decrement(value)) | |
} | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(Counter) |
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 { configure, shallow } from 'enzyme' | |
import Adapter from 'enzyme-adapter-react-16' | |
configure({ adapter: new Adapter() }) | |
import { Counter } from './Counter' | |
describe('<Counter />', () => { | |
it('should mount', () => { | |
const props = { | |
counter: 10, | |
increment: () => 1, | |
decrement: () => 1 | |
} | |
const wrapper = shallow(<Counter {...props} />) | |
expect(wrapper.length).toEqual(1) | |
}) | |
it('should call increment', () => { | |
const props = { | |
counter: 10, | |
increment: () => jest.fn(), | |
decrement: () => jest.fn() | |
} | |
const wrapper = shallow(<Counter {...props} />) | |
wrapper.find('.increment').simulate('click') | |
expect(props.increment.mock.calls.length).toEqual(1) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O erro ocorre na linha 31 do Counter.test.js.
A msg recebida é: TypeError: Cannot read property 'calls' of undefined