Skip to content

Instantly share code, notes, and snippets.

@gustavocardoso
Created June 27, 2018 14:41
Show Gist options
  • Save gustavocardoso/4cdd17694f163af876fcc9e763304a75 to your computer and use it in GitHub Desktop.
Save gustavocardoso/4cdd17694f163af876fcc9e763304a75 to your computer and use it in GitHub Desktop.
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)
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)
})
})
@gustavocardoso
Copy link
Author

O erro ocorre na linha 31 do Counter.test.js.
A msg recebida é: TypeError: Cannot read property 'calls' of undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment