Skip to content
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

Improve error message for length assertion #73

Conversation

herintsoa-hasina
Copy link

@herintsoa-hasina herintsoa-hasina commented Mar 7, 2018

Hello guys,

I like very much the js-must project as a test tool in my own project. When searching in the source code, I was interested to make the length assert error message more expressive. I modified the Must.prototype.length implementation to improve the ouput of the error message assertion. In fact, it will be more interesting to show the difference between the expected and the actual length when the assertion fails.

For example, [2,'a'].must.have.length(3) should return this output

AssertionError: [2,"a"] must have length of 3
+ expected - actual
-2
+3

Or "hello".must.have.length(3) with the output

AssertionError: "hello" must have length of 3
+ expected - actual
-5
+3

The value of the actual length is also included as a parameter of the
assert which is used inside the Must.prototype.length implementation.
As a result, the error output shows the difference between the actual
and the expected length.
@moll moll merged commit ee29422 into moll:master Nov 2, 2020
@moll
Copy link
Owner

moll commented Nov 2, 2020

Hey! Sorry for the belated reply. That seemed like a reasonable suggestion. Thank you! I've merged it in and will release a new version shortly.

@moll
Copy link
Owner

moll commented Nov 2, 2020

Btw, are you the same person as https://github.com/mrHerintsoaHasina?

@herintsoa-hasina
Copy link
Author

herintsoa-hasina commented Nov 2, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants