Last active
June 16, 2017 09:51
-
-
Save stipsan/9fe73db12fe931df727055e95a022986 to your computer and use it in GitHub Desktop.
Testing with Jest: Tip #11
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 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') | |
}) |
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 { 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