Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oieduardorabelo/f246a2246e3658f9cd89bfd4c5536057 to your computer and use it in GitHub Desktop.
Save oieduardorabelo/f246a2246e3658f9cd89bfd4c5536057 to your computer and use it in GitHub Desktop.
Testando com Jest: Dica #11
import renderer from 'react-test-renderer'
import NotificationsContainer from '../NotificationsContainer'
// nós podemos simplesmente retornar o compoente, já que
// passamos dispatch como prop diretamente
jest.mock('react-redux', () => component => component)
it('should render correctly', () => {
const dispatch = jest.fn()
const component = renderer.create(
<NotificationsContainer dispatch={dispatch} />
)
expect(component.toJSON()).toMatchSnapshot()
expect(dispatch).toHaveBeenCalled()
expect(dispatch.mock.calls).toMatchSnapshot('dispatch was called correctly')
})
import { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import Notifications from './Notifications'
class NotificationsContainer extends Component {
static propTypes = {
dispatch: PropTypes.func.isRequired
}
componentDidMount() {
this.props.dispatch({ type: 'REQUEST_NOTIFICATIONS' })
}
render() {
return <Notifications />
}
}
export default connect()(NotificationsContainer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment