I have a complex predicate in JavaScript that chains various tests against a value.
I'd love to log where in the expression it fails, if it fails. Sort of like testing libraries that log out where an exception fails.
Is there some sort of reflection I can do to extract some pretty description of what caused an expression to fail?
e.g.,
const predicate = a.foo == 1 && a.bar < 3 && someOtherPredicate(a.bar)
// if predicate == false, console.log ->
// "error: b.bar < 3 evaluated to false"
(I'm actually interested in doing this in Typescript, but want to see what features JavaScript has that could enable this)
why don't you try debugging to check where this expression actually failing. put debugger; before your expression open up the console tab and keep observing your output w.r.t. your input