-
-
Save oieduardorabelo/1e00512170837e69454e598735fe7121 to your computer and use it in GitHub Desktop.
Testando com Jest: Dica #10
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 Input from '../Input' | |
it('should render correctly', () => { | |
const component = renderer.create(<Input />) | |
expect(component.toJSON()).toMatchSnapshot() | |
// getInstance está retornando o objeto `this` que você tem no seu componente | |
// significando que todos os métodos que você tem no seu componente, podem ser | |
// acesso aqui, incluindo props! | |
const instance = component.getInstance() | |
expect(instance.state).toMatchSnapshot('initial state') | |
instance.handleChange({ target: { value: '[email protected]' } }) | |
expect(instance.state).toMatchSnapshot('updated state') | |
}) |
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' | |
export default class Input extends Component { | |
state = { value: '' } | |
handleChange = event => this.setState({ value: event.target.value }) | |
render() { | |
return ( | |
<div> | |
<label>Email</label> | |
<input | |
type="email" | |
onChange={this.handleChange} | |
value={this.state.value} | |
/> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment