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

error message for assert.calledWith breaks when representations are equal #2084

Closed
rensbaardman opened this issue Sep 19, 2019 · 6 comments
Closed

Comments

@rensbaardman
Copy link

rensbaardman commented Sep 19, 2019

Describe the bug
When the (string) representations of the expected outcome and the actual outcome of e.g. assert.calledWith() are equal, the resulting error message is very confusing and hinting at a bug in the display logic. Instead of <red>actual</red> <green>expected</green> (with <color>...</color> my attempt at showing the expected terminal output color), it displays <black>actual</black>, as if the outcome is actually correct.

To Reproduce
Running the following with node:

const sinon = require('sinon')

mySpy = sinon.spy()
mySpy(1234)
sinon.assert.calledWith(mySpy, '1234')

generates this output:

        throw error;
        ^

AssertError: expected spy to be called with arguments 
1234
    at Object.fail [...]

Expected behavior
I expected something like this:

        throw error;
        ^

AssertError: expected spy to be called with arguments 
<red>1234</red> <green>1234</green>
    at Object.fail [...]

so <red>1234</red> <green>1234</green> instead of <black>1234</black>.

Or, as assert.match does it (run e.g. sinon.assert.match(1234, '1234')):

        throw error;
        ^

AssertError: expected value to match
    expected = 1234
    actual = 1234
    at Object.fail [...]

It would be even better if it recognizes when string representations are equal, since this remains a confusing way to display the error: on first sight, it seems the actual outcome is equal to expected outcome, when it is not! Or simply include apostrophes for strings.

Compare how Chai handles this:

const assert = require('chai').assert;
assert.strictEqual(1234, '1234')

throws:

AssertionError: expected 1234 to equal '1234'

Context (please complete the following information):

  • Library version: 7.4.2
  • Environment: macOS 10.11.6, Node v10.16.0
@rensbaardman rensbaardman changed the title AssertError message on assert.calledWith confusing when representations are equal error message for assert.calledWith breaks when representations are equal Sep 19, 2019
rensbaardman added a commit to rensbaardman/Stoic that referenced this issue Sep 19, 2019
Boy, this took me a while. The main problem was
that applyStatusChange is async, which I hadn't
taken into account. Therefore, the assertion was
run before applyStatusChange had done its work.
Stupid error of me.

I also made some mistakes for the tabId: I didn't
resolve the browser.tabs.query-mock with the variable,
but with a hand coded integer.

What made this even more frustrating to debug, was a bug
in Sinon I found through this: comparing '1234' to 1234
gave a very confusing AssertionError message, as if
everything was okay. See sinonjs/sinon#2084
for the bug I filed.
@stale
Copy link

stale bot commented Nov 18, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@fatso83
Copy link
Contributor

fatso83 commented Dec 3, 2019

@rensbaardman Would you like to have a stab at fixing this? I think it's a one-line fix, preferably with a small regression test.

@rensbaardman
Copy link
Author

rensbaardman commented Dec 18, 2019

Sorry for the late reply – I certainly want to take a look at it, but I am quite busy right now so can't promise a quick resolution.

@romanbalayan
Copy link
Contributor

Seems like this is still an issue?

@romanbalayan
Copy link
Contributor

Can I reopen a pull request for this, most of the work has actually already been done by @rgroothuijsen.

fatso83 pushed a commit that referenced this issue Oct 13, 2020
…tual value is equal, fixing issue #2084 (#2303)

Co-authored-by: Roman Balayan <roman.balayan@paymaya.com>
@mroderick
Copy link
Member

This has been fixed with #2303

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

No branches or pull requests

4 participants