Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const defaultProps = {
- username: '',
- email: '',
- password: '',
- passwordConfirmation: '',
- submit: jest.fn(),
- onUsernameChange: jest.fn(),
- onEmailChange: jest.fn(),
- onPasswordChange: jest.fn(),
- onPasswordConfirmationChange: jest.fn(),
- };
- describe('signup form', () => {
- //[...]
- test('should call the onUsernameChange prop when username input receives change event', () => {
- const onUsernameChange = jest.fn();
- const wrapper = shallow(<SignupForm {...defaultProps} onUsernameChange={onUsernameChange} />);
- const usernameInput = wrapper.find('input[name="username"]');
- usernameInput.simulate('change', { some: 'data' });
- expect(onUsernameChange).toHaveBeenCalledWith({ some: 'data' });
- });
- test('should call the onEmailChange prop when email input receives change event', () => {
- const onEmailChange = jest.fn();
- const wrapper = shallow(<SignupForm {...defaultProps} onEmailChange={onEmailChange} />);
- const emailInput = wrapper.find('input[name="email"]');
- emailInput.simulate('change', { some: 'data' });
- expect(onEmailChange).toHaveBeenCalledWith({ some: 'data' });
- });
- test('should call the onPasswordChange prop when password input receives change event', () => {
- const onPasswordChange = jest.fn();
- const wrapper = shallow(<SignupForm {...defaultProps} onPasswordChange={onPasswordChange} />);
- const passwordInput = wrapper.find('input[name="password"]');
- passwordInput.simulate('change', { some: 'data' });
- expect(onPasswordChange).toHaveBeenCalledWith({ some: 'data' });
- });
- test('should call the onPasswordConfirmationChange prop when password confirmation input receives change event', () => {
- const onPasswordConfirmationChange = jest.fn();
- const wrapper = shallow(
- <SignupForm {...defaultProps} onPasswordConfirmationChange={onPasswordConfirmationChange} />,
- );
- const passwordConfirmationInput = wrapper.find('input[name="passwordConfirmation"]');
- passwordConfirmationInput.simulate('change', { some: 'data' });
- expect(onPasswordConfirmationChange).toHaveBeenCalledWith({ some: 'data' });
- });
- });
Add Comment
Please, Sign In to add comment