test(testFunctions): display stringified arguments in error message#2442
Merged
rubiin merged 1 commit intovalidatorjs:masterfrom Aug 25, 2024
Merged
Conversation
this now shows the actual passed arguments, instead of [Object object] in case a test with a options object fails
WikiRik
approved these changes
Aug 25, 2024
Member
WikiRik
left a comment
There was a problem hiding this comment.
Looks good to me. Maybe you can do an example commit (in this PR and reverting it afterwards or in a separate temporary PR) with a failing test so we can check that it works well on CI?
Contributor
Author
|
ok, will try to do this in a separate PR, that we can then just delete |
rubiin
approved these changes
Aug 25, 2024
Contributor
Author
WikiRik
approved these changes
Aug 25, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 failedAfter:
Error: validator.isDate("2024/05/01", {"delimiters":["/"," "],"format":"YYYY/MM/DD","strictMode":false}) passed but should have failedThis 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