-
-
Save oieduardorabelo/f246a2246e3658f9cd89bfd4c5536057 to your computer and use it in GitHub Desktop.
Testando com Jest: Dica #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' | |
// 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') | |
}) |
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