chai-spies icon indicating copy to clipboard operation
chai-spies copied to clipboard

When with fails, report not only the expected, but the actual.

Open ExploreMqt opened this issue 10 years ago • 9 comments
trafficstars

ExploreMqt avatar Jul 10 '15 17:07 ExploreMqt

Hey @ExploreMqt thanks for the pr

You can use #{act} instead, and then pass it as another argument, which is more the chai convention. An example

keithamus avatar Jul 11 '15 11:07 keithamus

Thanks. Will do

-----Original Message----- From: "Keith Cirkel" [email protected] Sent: ‎7/‎11/‎2015 7:25 AM To: "chaijs/chai-spies" [email protected] Cc: "Jim Argeropoulos" [email protected] Subject: Re: [chai-spies] When with fails, report not only the expected, butthe actual. (#29)

Hey @ExploreMqt thanks for the pr You can use #{act} instead, and then pass it as another argument, which is more the chai convention. An example — Reply to this email directly or view it on GitHub.

ExploreMqt avatar Jul 11 '15 12:07 ExploreMqt

Sorry to be a pain @ExploreMqt - could you also add some tests for this? It'd be nice to have some tests to back up the code is doing what it is meant to. Let me know if you need help with this.

keithamus avatar Jul 24 '15 22:07 keithamus

You are not a pain. I was just at a loss as to where to put said test

-----Original Message----- From: "Keith Cirkel" [email protected] Sent: ‎7/‎24/‎2015 5:09 PM To: "chaijs/chai-spies" [email protected] Cc: "Jim Argeropoulos" [email protected] Subject: Re: [chai-spies] When with fails, report not only the expected, butthe actual. (#29)

Sorry to be a pain @ExploreMqt - could you also add some tests for this? It'd be nice to have some tests to back up the code is doing what it is meant to. Let me know if you need help with this. — Reply to this email directly or view it on GitHub.

ExploreMqt avatar Jul 25 '15 02:07 ExploreMqt

Here all all the .with tests, some of them (like this one) look at the failure error message, and test what it says. You'd just need to extend these with what you'd expect your new error messages to say. So rather than

  }).should.throw(chai.AssertionError, /have been called with/);

You should write something like:

  }).should.throw(chai.AssertionError, /have been called with [4] but got [[1], [2], [3]]/);

keithamus avatar Jul 25 '15 09:07 keithamus

Hey @ExploreMqt do you think you will have some time available to update this?

keithamus avatar Oct 13 '15 19:10 keithamus

I haven't figured out a satisfactory solution for myself. So not at this point

-----Original Message----- From: "Keith Cirkel" [email protected] Sent: ‎10/‎13/‎2015 3:14 PM To: "chaijs/chai-spies" [email protected] Cc: "Jim Argeropoulos" [email protected] Subject: Re: [chai-spies] When with fails, report not only the expected, butthe actual. (#29)

Hey @ExploreMqt do you think you will have some time available to update this? — Reply to this email directly or view it on GitHub.

ExploreMqt avatar Oct 13 '15 19:10 ExploreMqt

@ExploreMqt, I had similar issues, but a went further. I wonder if you could review my solution ( https://github.com/chaijs/chai-spies/pull/52 )

robcolburn avatar Apr 27 '16 19:04 robcolburn

@keithamus, I tried to go down the ${act} route but found it too limiting. Once you've passed the buck to ${act} you can give it guidance and it ultimately results which are less than helpful. Our ${act} isn't singular here, instead we are inspecting a history of calls to this function. Since a spied-on function may have been called several times, we are really asking if has been called "at least one" (default), or "every time" (with .always modifier.

In digging around I found many examples in chai's own code-base, as well as other plugins chai-properties that directly call _.inspect. This turns out to be helpful too because we can format the call history instead of just calling it an array (which is confusing in an output).

I wonder if you can review my solution here https://github.com/chaijs/chai-spies/pull/52

robcolburn avatar Apr 27 '16 19:04 robcolburn