react-logo/frontend/src/components/UserForm.test.js

35 lines
1.1 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('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);
});
});
});