form-schema
Advanced tools
Comparing version
{ | ||
"name": "form-schema", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "A form validation tool that traverses the data according to the schema and calls the validators.", | ||
"main": "lib/index.js", | ||
"webpack": "src/index.js", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "browser": "scripts/browser", |
@@ -293,9 +293,14 @@ import chai from 'chai'; | ||
describe('validators', () => { | ||
it('should supply field data and entire form data', () => { | ||
it('should supply field data and its ancestors to the validator', () => { | ||
const data = { | ||
id: 'id1', | ||
name: 'ABC', | ||
nested: { | ||
random: '123', | ||
}, | ||
arr: [3, 4, 5], | ||
}; | ||
const testValidator = (fieldData, dataRoot) => { | ||
dataRoot.should.equal(data); | ||
const rootFieldsValidator = (fieldData, ancestors) => { | ||
ancestors.should.have.length(1); | ||
ancestors[0].should.equal(data); | ||
return { | ||
@@ -305,5 +310,25 @@ isValid: true, | ||
}; | ||
const nestedFieldValidator = (fieldData, ancestors) => { | ||
ancestors.should.have.length(2); | ||
ancestors[0].should.equal(data.nested); | ||
ancestors[1].should.equal(data); | ||
return { | ||
isValid: true, | ||
}; | ||
}; | ||
const arrFieldValidator = (fieldData, ancestors) => { | ||
ancestors.should.have.length(2); | ||
ancestors[0].should.equal(data.arr); | ||
ancestors[1].should.equal(data); | ||
return { | ||
isValid: true, | ||
}; | ||
}; | ||
const schema = { | ||
id: field(testValidator).isRequired(), | ||
name: field(testValidator).isRequired(), | ||
id: field(rootFieldsValidator).isRequired(), | ||
name: field(rootFieldsValidator).isRequired(), | ||
nested: { | ||
random: field(nestedFieldValidator), | ||
}, | ||
arr: [field(arrFieldValidator)], | ||
}; | ||
@@ -310,0 +335,0 @@ const { isValid } = validate(data, schema); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
-50%33514
-20.46%463
-7.95%