Skip to content

Commit

Permalink
Remove tests for component level validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Valadas committed Feb 25, 2018
1 parent 154df87 commit 878e191
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 84 deletions.
17 changes: 1 addition & 16 deletions test/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ const InputField = Field(
}
);

const RequiredInputField = Field(
class extends React.Component {
constructor(props) {
super(props);
this.validators = [required()];
}

render() {
return (
<input {...this.props.element}/>
);
}
}
);

const SelectField = Field(
class extends React.Component {
options() {
Expand All @@ -49,4 +34,4 @@ const SelectField = Field(
}
);

export {InputField, RequiredInputField, SelectField};
export {InputField, SelectField};
69 changes: 1 addition & 68 deletions test/unit/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Enzyme from 'enzyme';
import {mount} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Form from '../../src/form';
import {InputField, SelectField, RequiredInputField} from '../fields';
import {InputField, SelectField } from '../fields';
import {required, minLength} from '../validators';

Enzyme.configure({ adapter: new Adapter() });
Expand Down Expand Up @@ -112,73 +112,6 @@ describe('Field', function() {
});
});

describe('with a validator defined in the wrapped component', () => {
beforeEach(() => {
this.wrapper = mount(
<Form>
<RequiredInputField name="banana" type="text"/>
</Form>
);
this.field = this.wrapper.instance().getField('banana');
});

it('should be invalid without a value', () => {
expect(this.field.validate()).to.be.false;
});

it('should be valid with a value', () => {
const event = {
type: 'change',
target: {value: 'peel'}
};
return this.field.handleChange(event)
.then(() => {
expect(this.field.validate()).to.be.true;
});
});

describe('and on the component tag', () => {
beforeEach(() => {
this.wrapper = mount(
<Form>
<RequiredInputField name="banana" type="text" validators={[minLength(5)]}/>
</Form>
);
this.field = this.wrapper.instance().getField('banana');
});

it('should have two validators', () => {
expect(this.field.validators).to.have.length(2);
});

it('should be invalid without a value', () => {
expect(this.field.validate()).to.be.false;
});

it('should be invalid with a value under 5 characters', () => {
const event = {
type: 'change',
target: {value: 'peel'}
};
return this.field.handleChange(event)
.then(() => {
expect(this.field.validate()).to.be.false;
});
});

it('should be valid with a value with 5 characters', () => {
const event = {
type: 'change',
target: {value: 'puree'}
};
return this.field.handleChange(event)
.then(() => {
expect(this.field.validate()).to.be.true;
});
});
});
});

describe('with initial values', () => {
beforeEach(() => {
const initialValues = {
Expand Down

0 comments on commit 878e191

Please sign in to comment.