54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
import { configure, mount } from 'enzyme';
|
|
import Adapter from 'enzyme-adapter-react-16';
|
|
|
|
configure({ adapter: new Adapter() });
|
|
|
|
import React from 'react';
|
|
import { ExtendedUserForm as UserForm } from './UserForm';
|
|
|
|
describe('<UserForm />', () => {
|
|
|
|
describe('submit', () => {
|
|
test('correctly submitted', () => {
|
|
const onSubmit = jest.fn();
|
|
const form = mount(<UserForm onSubmit={onSubmit} />);
|
|
|
|
form.find('[name="username"]').simulate('change', { target: { value: 'test' } });
|
|
form.find('[name="password"]').simulate('change', { target: { value: 'test' } });
|
|
form.find('[name="passwordVerification"]').simulate('change', { target: { value: 'test' } });
|
|
form.find('form').simulate('submit');
|
|
|
|
expect(onSubmit).toHaveBeenCalledWith({
|
|
username: 'test',
|
|
password: 'test',
|
|
passwordVerification: 'test'
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('username validation', () => {
|
|
|
|
test('empty username', () => {
|
|
const onSubmit = formData => console.log(formData);
|
|
const form = mount(<UserForm onSubmit={onSubmit} />);
|
|
|
|
form.find('[name="username"]').simulate('change', { target: { value: '' } });
|
|
|
|
const props = form.find('UserForm').props();
|
|
|
|
expect(props.form.errors.username.hasError).toBe(true);
|
|
});
|
|
|
|
test('non empty username', () => {
|
|
const onSubmit = formData => console.log(formData);
|
|
const form = mount(<UserForm onSubmit={onSubmit} />);
|
|
|
|
form.find('[name="username"]').simulate('change', { target: { value: 'foo' } });
|
|
|
|
const props = form.find('UserForm').props();
|
|
expect(props.form.errors.username.hasError).toBe(false);
|
|
});
|
|
|
|
});
|
|
});
|