Skip to content

Commit

Permalink
test(Field): getErrorStrs tests
Browse files Browse the repository at this point in the history
- clean up eslint errors in other tests
  • Loading branch information
jdkahn committed May 15, 2019
1 parent 5560353 commit 4d65cff
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/field/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getValueFromEvent(e) {
}

function cloneAndAddKey(element) {
if (element && isValidElement(element) && !element.props.key) {
if (element && isValidElement(element)) {
return cloneElement(element, { key: 'error' });
}
return element;
Expand Down
66 changes: 34 additions & 32 deletions test/field/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ Enzyme.configure({ adapter: new Adapter() });

const FormItem = Form.Item;

/* eslint-disable react/jsx-filename-extension */
/*global describe it */
describe('field', () => {
describe('render', () => {
it('should support Form', done => {
it('should support Form', function(done) {
class Demo extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -64,7 +66,7 @@ describe('field', () => {

done();
});
it('should support PureComponent', done => {
it('should support PureComponent', function(done) {
class Demo extends React.PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -95,7 +97,7 @@ describe('field', () => {
done();
});

it('should support origin input/checkbox/radio', done => {
it('should support origin input/checkbox/radio', function(done) {
class Demo extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -155,8 +157,8 @@ describe('field', () => {
});
});
describe('init', () => {
it('init(input)', done => {
let field = new Field();
it('init(input)', function(done) {
let field = new Field(this);
let inited = field.init('input');

assert(typeof inited['ref'] === 'function');
Expand All @@ -177,8 +179,8 @@ describe('field', () => {

done();
});
it('initValue', done => {
let field = new Field();
it('initValue', function(done) {
let field = new Field(this);
let inited = field.init('input', { initValue: 2 });

assert(inited.value === 2);
Expand All @@ -189,8 +191,8 @@ describe('field', () => {

done();
});
it('valueName', done => {
let field = new Field();
it('valueName', function(done) {
let field = new Field(this);
let inited = field.init('input', {
initValue: true,
valueName: 'checked',
Expand All @@ -200,8 +202,8 @@ describe('field', () => {
done();
});

it('props', done => {
let field = new Field();
it('props', function(done) {
let field = new Field(this);
let inited = field.init('input', {
initValue: true,
valueName: 'checked',
Expand All @@ -216,9 +218,9 @@ describe('field', () => {
done();
});

it('custom Event: onChange', done => {
it('custom Event: onChange', function(done) {
const onChange = sinon.spy();
let field = new Field(null, { onChange });
let field = new Field(this, { onChange });
let inited = field.init('input', {
props: {
onChange,
Expand All @@ -234,7 +236,7 @@ describe('field', () => {
assert(field.getValue('input') === 'test');
assert(onChange.callCount === 2);

let field2 = new Field(null, {
let field2 = new Field(this, {
onChange: (name, value) => {
assert(value === 'test');
},
Expand All @@ -260,8 +262,8 @@ describe('field', () => {
done();
});

it('getValueFromEvent', done => {
let field = new Field(null, {
it('getValueFromEvent', function(done) {
let field = new Field(this, {
onChange: (name, value) => {
assert(value === 'test!');
},
Expand All @@ -286,8 +288,8 @@ describe('field', () => {
done();
});

it('rules', done => {
let field = new Field();
it('rules', function(done) {
let field = new Field(this);
field.init('input', {
rules: [
{
Expand All @@ -311,8 +313,8 @@ describe('field', () => {
});

describe('behaviour', () => {
it('getValue & getValues & setValue & setValues', done => {
let field = new Field();
it('getValue & getValues & setValue & setValues', function(done) {
let field = new Field(this);
field.init('input', { initValue: 1 });
field.init('input2', { initValue: 2 });
field.init('input3.name', { initValue: 3 });
Expand All @@ -331,8 +333,8 @@ describe('field', () => {
done();
});

it('setError & setErrors & getError & getErrors', done => {
let field = new Field();
it('setError & setErrors & getError & getErrors', function(done) {
let field = new Field(this);
field.setError('input', 'error1');

field.init('input');
Expand All @@ -356,8 +358,8 @@ describe('field', () => {

done();
});
it('getState', done => {
let field = new Field();
it('getState', function(done) {
let field = new Field(this);

field.init('input');

Expand All @@ -369,8 +371,8 @@ describe('field', () => {
done();
});

it('validate', done => {
let field = new Field();
it('validate', function(done) {
let field = new Field(this);
let inited = field.init('input', {
rules: [{ required: true, message: 'cant be null' }],
});
Expand Down Expand Up @@ -413,8 +415,8 @@ describe('field', () => {
done();
});

it('reset', done => {
let field = new Field();
it('reset', function(done) {
let field = new Field(this);
field.init('input', { initValue: '1' });

field.reset();
Expand All @@ -428,8 +430,8 @@ describe('field', () => {

done();
});
it('remove', done => {
let field = new Field();
it('remove', function(done) {
let field = new Field(this);
field.init('input', { initValue: 1 });
field.init('input2', { initValue: 1 });
field.init('input3', { initValue: 1 });
Expand All @@ -444,8 +446,8 @@ describe('field', () => {

done();
});
it('spliceArray', done => {
let field = new Field();
it('spliceArray', function(done) {
let field = new Field(this);
field.init('input.0', { initValue: 0 });
field.init('input.1', { initValue: 1 });
field.init('input.2', { initValue: 2 });
Expand Down
33 changes: 17 additions & 16 deletions test/field/options-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import Field from '../../src/field/index';

Enzyme.configure({ adapter: new Adapter() });

/*global describe it */
describe('options', () => {
it('should support autoUnmount', done => {
it('should support autoUnmount', function(done) {
class Demo extends React.Component {
state = {
show: true,
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('options', () => {
wrapper.find('button').simulate('click');
});

it('should support autoUnmount with same name', done => {
it('should support autoUnmount with same name', function(done) {
class Demo extends React.Component {
state = {
show: true,
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('options', () => {
done();
});

it('should support autoUnmount=false', done => {
it('should support autoUnmount=false', function(done) {
class Demo extends React.Component {
state = {
show: true,
Expand All @@ -96,7 +97,7 @@ describe('options', () => {
) : null}
<button
onClick={() => {
console.log(this.field);
// console.log(this.field);
assert(
this.field.getValue('input2') === 'test2'
);
Expand All @@ -115,7 +116,7 @@ describe('options', () => {
done();
});

it('scrollToFirstError', done => {
it('scrollToFirstError', function(done) {
class Demo extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -154,7 +155,7 @@ describe('options', () => {
done();
});

it('values', done => {
it('values', function(done) {
class Demo extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -188,8 +189,8 @@ describe('options', () => {
});

describe('should support parseName', () => {
it('getValues', done => {
const field = new Field(null, { parseName: true });
it('getValues', function(done) {
const field = new Field(this, { parseName: true });
field.init('user.name', { initValue: 'frankqian' });
field.init('user.pwd', { initValue: 12345 });
field.init('option[0]', { initValue: 'option1' });
Expand All @@ -206,8 +207,8 @@ describe('options', () => {

done();
});
it('setValues', done => {
const field = new Field(null, { parseName: true });
it('setValues', function(done) {
const field = new Field(this, { parseName: true });
field.init('user.name', { initValue: 'frankqian' });
field.init('user.pwd', { initValue: 12345 });
field.init('option[0]', { initValue: 'option1' });
Expand All @@ -233,8 +234,8 @@ describe('options', () => {
});

describe('should support autoValidate=false', () => {
it('options.autoValidate=true', done => {
const field = new Field(null, { autoValidate: true });
it('options.autoValidate=true', function(done) {
const field = new Field(this, { autoValidate: true });
const inited = field.init('input', { rules: [{ minLength: 10 }] });

const wrapper = mount(<Input {...inited} />);
Expand All @@ -248,8 +249,8 @@ describe('options', () => {

done();
});
it('options.autoValidate=false', done => {
const field = new Field(null, { autoValidate: false });
it('options.autoValidate=false', function(done) {
const field = new Field(this, { autoValidate: false });
const inited = field.init('input', { rules: [{ minLength: 10 }] });

const wrapper = mount(<Input {...inited} />);
Expand All @@ -266,8 +267,8 @@ describe('options', () => {

done();
});
it('props.autoValidate=false', done => {
const field = new Field(null);
it('props.autoValidate=false', function(done) {
const field = new Field(this);
const inited = field.init('input', {
autoValidate: false,
rules: [{ minLength: 10 }],
Expand Down
12 changes: 6 additions & 6 deletions test/field/rules-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Field from '../../src/field/index';
Enzyme.configure({ adapter: new Adapter() });

describe('rules', () => {
it('required', done => {
let field = new Field();
it('required', function(done) {
let field = new Field(this);
let inited = field.init('input', {
rules: [
{
Expand Down Expand Up @@ -39,8 +39,8 @@ describe('rules', () => {

done();
});
it('triger', done => {
let field = new Field();
it('triger', function(done) {
let field = new Field(this);
let inited = field.init('input', {
rules: [
{
Expand Down Expand Up @@ -73,8 +73,8 @@ describe('rules', () => {

done();
});
it('validator', done => {
let field = new Field();
it('validator', function(done) {
let field = new Field(this);
let inited = field.init('input', {
rules: [
{
Expand Down
Loading

0 comments on commit 4d65cff

Please sign in to comment.