-
Notifications
You must be signed in to change notification settings - Fork 32
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
TypeError: predicate is not a function #6
Comments
Thanks for the feedback, will have a look. |
You need to change the const spected = require('spected').default
const isGreaterThan = a => b => b > a
const hasCapitalLetter = text => x => true
const validationRules = {
name: [
[ isGreaterThan(5),
`Minimum Name length of 6 is required.`
],
],
random: [
[ isGreaterThan(7), 'Minimum Random length of 8 is required.' ],
[ hasCapitalLetter, 'Random should contain at least one uppercase letter.' ],
]
}
const inputData = { name: 'abcdef', random: 'z'}
const res = spected(validationRules, inputData)
console.log(res) |
Ah, I see what is happening, thanks! What do you think about an internal check like, if (typeof predicate != "function") {
throw new Error("The validator you supplied is not a function")
} ? Hard to tell at this early stage, but it seems like it could be a common error. |
Yes, it makes sense to handle invalid rules. In dev mode we can issue a console warning. Added a warning function https://github.com/25th-floor/spected/blob/master/src/utils/warning.js In any case we should skip validating and return true instead, treat it the same as if no predicate function was defined. Currently passing in |
In
index.js
,When I run
node index.js
, I get this error:The text was updated successfully, but these errors were encountered: