test(testFunctions): display stringified arguments in error message #2442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
the error message that the testFunctions currently throws, when a test case fails is currently not correctly displaying options objects, even though the intention clearly is there.
This pull request properly implements this now, by stringifying the arguments, making sure they can get correctly printed as string.
Before
Error: validator.isDate("2024/05/01", [Object object]) passed but should have failed
After:
Error: validator.isDate("2024/05/01", {"delimiters":["/"," "],"format":"YYYY/MM/DD","strictMode":false}) passed but should have failed
This is achieved by a tiny helper function that maps through the args and JSON.stringifys them.
All of these are available since node v0.10, so we still are compatible with that (ancient :)) version:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#browser_compatibility
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
I would've like to replace the "format" function with template literals as well, but these were not available in node 0.10.0 (which is the minimum engine mentioned in the package.json) yet, but only came with node 4.
Checklist