Created
September 2, 2016 13:29
-
-
Save sminutoli/98e2a3c2c2c13b409bfc1a7b35b59590 to your computer and use it in GitHub Desktop.
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
const props = { | |
username: 'theuser', | |
password: 'thepass', | |
onChange: expect.createSpy(), | |
onSignIn: expect.createSpy() | |
}; | |
const wrapper = shallow(<Login {...props}/>); | |
it('should trigger onChange when any of the input changes', ()=>{ | |
wrapper.find('.login__user').simulate('change', { target:{ name: 'username', value: 'asd'} }); | |
expect(props.onChange).toHaveBeenCalledWith({username: 'asd'}); | |
props.onChange.reset(); | |
wrapper.find('.login__password').simulate('change', { target:{ name: 'password', value: 'asd'} }); | |
expect(props.onChange).toHaveBeenCalledWith({password: 'asd'}); | |
}); | |
it('should call onSignIn with user and password', ()=>{ | |
wrapper.find('.login__form').simulate('submit', { preventDefault: expect.createSpy() }); | |
const expected = { username: props.username, password: props.password }; | |
expect(props.onSignIn).toHaveBeenCalledWith(expected); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment