-
-
Notifications
You must be signed in to change notification settings - Fork 696
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
expect('word$').to.equal('xxx') failure message broken #560
Comments
Hey @jurko-gospodnetic thanks for the issue. Well, this was a tricky one to figure out! The offending lines are here; https://github.com/chaijs/chai/blob/master/lib/chai/utils/getMessage.js#L45-L48. The reason this is happening is because > chai.util.inspect('foo$')
'`\foo$\'" Of course, as I mentioned before, 'x'.replace('x', '$\'') You'd expect that to equal The FixOkay, so I think the easiest way to fix this is to subvert the String behaviour, and give the replace function a different argument. We can give it a function that returns a String, and everything works exactly as you'd expect. So I'd recommend changing L45-48 from: msg = msg
.replace(/#{this}/g, objDisplay(val))
.replace(/#{act}/g, objDisplay(actual))
.replace(/#{exp}/g, objDisplay(expected)); To: msg = msg
.replace(/#{this}/g, function () { return objDisplay(val) })
.replace(/#{act}/g, function () { objDisplay(actual) })
.replace(/#{exp}/g, function () { objDisplay(expected) }); This should fix the problem outright. As part of this, I would expect to see tests as well - our test suite for @jurko-gospodnetic if you want to make a PR to fix this problem, that'd be awesome. Doing so will net you a place in our amazing hall of fame where all of our great contributors go 🤘. |
ROFL... omg... what an amazing developer pitch... 👍 Ok... can't resist - I'll take a look now. 😆 |
Got pull request #570 up for this. |
Might want to remove the |
I keep them around for posterity - we can use them to track the issues that wanted a pr and got one 😄 |
Executing
expect('word$').to.equal('xxx')
will give a broken failure message:AssertionError: expected 'word to equal 'xxx' to equal 'xxx'
The final
$
sign seems to be used like some internal placeholder and expanded incorrectly.The text was updated successfully, but these errors were encountered: