Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement