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

Add better diffing for calledWith and calledWithExactly failures #124

Open
bskiff opened this issue May 4, 2018 · 7 comments · May be fixed by #141
Open

Add better diffing for calledWith and calledWithExactly failures #124

bskiff opened this issue May 4, 2018 · 7 comments · May be fixed by #141

Comments

@bskiff
Copy link

bskiff commented May 4, 2018

Currently when a test fails it provides output the following way:
e.g.

const fooObject = {
    foo: 'foo'
};
const barObject = {
    bar: 'bar'
};
const stub = sinon.stub();

stub(fooObject);

expect(stub).to.be.calledWithExactly(barObject);

prints

AssertionError: expected stub to have been called with exact arguments { bar: "bar" }
{ foo: "foo" } { bar: "bar" }

It would be nice if this was a proper diff similar to what Chai's deep equal assertions provide.
e.g.

const fooObject = {
    foo: 'foo'
};
const barObject = {
    bar: 'bar'
};

expect(fooObject).to.deep.equal(barObject);

prints

 AssertionError: expected { foo: 'foo' } to deeply equal { bar: 'bar' }                        
 + expected - actual                                                                           
                                                                                               
  {                                                                                            
 -  "foo": "foo"                                                                               
 +  "bar": "bar"                                                                               
  }                                                                                             

Editors such as IntelliJ IDEA have support for the latter style and will provide a nicely formatted diff in their diffing tools if that convention is followed.

@troynguyen8
Copy link

Any status on this? My team is facing this issue. Using calledWithExactly is much cleaner than expect(spy.lastCall.args).to.equal(expectedCall)

@domenic
Copy link
Collaborator

domenic commented May 6, 2019

@kuceb kuceb linked a pull request Jun 6, 2019 that will close this issue
1 task
@kuceb
Copy link

kuceb commented Jun 6, 2019

I've got a PR open here #141

@AdRaslan
Copy link

I had the same problem and it was solved by using JSON.stringify(). Try this:

const fooObject = {
foo: 'foo'
};
const barObject = {
bar: 'bar'
};
const stub = sinon.stub();

stub(fooObject);

expect(stub).to.be.calledWithExactly(JSON.stringify(barObject));

@benjick
Copy link

benjick commented Jan 13, 2022

Any news on this?

@alannaidon
Copy link

Any news? 👀

@eliasm307
Copy link

Any news on this?

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 a pull request may close this issue.

8 participants