Skip to content

Instantly share code, notes, and snippets.

@sminutoli
Created September 2, 2016 13:29
Show Gist options
  • Save sminutoli/98e2a3c2c2c13b409bfc1a7b35b59590 to your computer and use it in GitHub Desktop.
Save sminutoli/98e2a3c2c2c13b409bfc1a7b35b59590 to your computer and use it in GitHub Desktop.
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