-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does this have support for yup.ref #2
Comments
Hey, thanks for the issue. For a quick test, I've copied the unit test and while it did succeed (all green), I had to change one detail: Every yup-ast schema is an Array of Arrays, but the -['yup.linkedGreaterThan', ['yup.ref', 'testValueSimple']],
+['yup.linkedGreaterThan', [['yup.ref', 'testValueSimple']]], |
It works! However, what I'm trying to do is a slightly more complicated, and I'm not sure whether it was supported in the previous version either. function allLessThan(refs, msg) {
return this.test({
test: function(val) {
let value = val
refs.forEach( ref => {
value += this.resolve(ref);
})
return 10 > value
},
message: msg || 'all must be less than 10',
});
}
yup.addMethod(yup.number, 'allLessThan', allLessThan);
const schema = transformAll([['yup.object', {
foo: [['yup.number'], ['yup.allLessThan', ['refs', [['yup.ref', 'baz']], [['yup.ref', 'bar']]] ]],
bar: [['yup.number'], ['yup.required']],
baz: [['yup.number'], ['yup.required']],
}]]);
const testObj = {
foo: 1,
bar: 1,
baz: 1,
}
console.log(schema.isValidSync(testObj)) I'd like my test function to be able to accept an arbitrary number of refs as an array. Maybe this case is outside the scope of functionality you want to support, I'm not sure. |
Alright, I've tested the following and I seem to have found "the issue": function allLessThan(...refs) {
return this.test({
test: function(val) {
let value = val
refs.forEach( ref => {
value += this.resolve(ref);
})
return 10 > value
},
message: 'all must be less than 10',
});
}
yup.addMethod(yup.number, 'allLessThan', allLessThan);
const schema = transformAll([['yup.object', {
foo: [['yup.number'], ['yup.allLessThan', [['yup.ref', 'baz']], [['yup.ref', 'bar']]] ],
bar: [['yup.number'], ['yup.required']],
baz: [['yup.number'], ['yup.required']],
}]]);
const testObj = {
foo: 1,
bar: 1,
baz: 1,
};
expect(schema.isValidSync(testObj)).toEqual(true); The package does not evaluate nested yup-ast schemas ( |
Great! I really appreciate it. |
🎉 This issue has been resolved in version 1.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I'm referring to functionality like that seen here: https://github.com/WASD-Team/yup-ast/blob/master/source/tests/converter.test.js#L518
What I'm trying to do is refer to multiple fields so that I can run them through a custom yup method (which does seem to be working) and test whether they, all together, sum to greater than some value.
And fwiw, thanks for taking over this codebase, glad to have found this repo.
The text was updated successfully, but these errors were encountered: