Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. const props = {
  2. username: 'theuser',
  3. password: 'thepass',
  4. onChange: expect.createSpy(),
  5. onSignIn: expect.createSpy()
  6. };
  7. const wrapper = shallow(<Login {...props}/>);
  8.  
  9. it('should trigger onChange when any of the input changes', ()=>{
  10. wrapper.find('.login__user').simulate('change', { target:{ name: 'username', value: 'asd'} });
  11. expect(props.onChange).toHaveBeenCalledWith({username: 'asd'});
  12. props.onChange.reset();
  13.  
  14. wrapper.find('.login__password').simulate('change', { target:{ name: 'password', value: 'asd'} });
  15. expect(props.onChange).toHaveBeenCalledWith({password: 'asd'});
  16. });
  17. it('should call onSignIn with user and password', ()=>{
  18. wrapper.find('.login__form').simulate('submit', { preventDefault: expect.createSpy() });
  19. const expected = { username: props.username, password: props.password };
  20. expect(props.onSignIn).toHaveBeenCalledWith(expected);
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement