form-schema
Advanced tools
Comparing version 0.1.2 to 1.0.0
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
33514
463