Skip to content

Instantly share code, notes, and snippets.

@stipsan
Last active June 16, 2017 09:51
Show Gist options
  • Save stipsan/9fe73db12fe931df727055e95a022986 to your computer and use it in GitHub Desktop.
Save stipsan/9fe73db12fe931df727055e95a022986 to your computer and use it in GitHub Desktop.
Testing with Jest: Tip #11
import renderer from 'react-test-renderer'
import NotificationsContainer from '../NotificationsContainer'
// we can just pass through the component since we pass dispatch prop directly
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