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

For rejected promises that were expected to be fulfilled, log the error that was thrown #128

Closed
JaKXz opened this issue Oct 24, 2015 · 5 comments

Comments

@JaKXz
Copy link

JaKXz commented Oct 24, 2015

  1) my project's component A should do something asynchronous:
     AssertionError: expected promise to be fulfilled but it was rejected with { Object (type, filename, ...) }

  2) my project's component B should do another asynchronous thing:
     AssertionError: expected promise to be fulfilled but it was rejected with { Object (type, filename, ...) }

It would be great if those printed the entire error object, just like when I add the catch block to my code to debug:

.then (data) -> doStuff data
.catch (error) -> console.log error

Apologies if this has been discussed already / is implemented and I just can't find it on the docs.

@keithamus
Copy link
Member

(@domenic this looks to be the same kind of issue as chaijs/sinon-chai#67).

From a quick glance, I think we could get this diffing properly by just passing true as an additional argument into assertion.assert on lines 76 and 80. I'm not sure if any extra work is involved - but I'd say @JaKXz if you're up for making a PR, give that a go and see if it does what you want 😄.

@JaKXz
Copy link
Author

JaKXz commented Oct 24, 2015

@keithamus I tried that locally - passing in true for the Assertion.prototype.assert method's showDiff parameter, but it didn't seem to work :(

        function assertIfNegated(assertion, message, extra) {
            assertion.assert(true, null, message, extra.expected, extra.actual, true);
        }

        function assertIfNotNegated(assertion, message, extra) {
            assertion.assert(false, message, null, extra.expected, extra.actual, true);
        }

I also noticed that config API has showDiff set to true already, and I don't think I've changed it anywhere in my project, so unless my understanding of the "diff" is wrong, I think there might be more work involved? Not 100% sure, will keep poking around.

@keithamus
Copy link
Member

@JaKXz it's worth reading chaijs/sinon-chai#67 as it offers a bit more context about the showDiff behaviour. If diffs aren't showing with true passed, then it could be that the reporter you're using doesn't output diffs. Which test runner and reporter are you using?

@tommysullivan
Copy link

I also have this problem using cucumber.js.

During testing to see if it was cucumber.js or chai-as-promised, I had two test cases:

In one test case, I simply returned a rejected promise to cucumber.js with an Error instance. This was automatically printed to the output using the toString() method of the error instance, which I verified was called on my error instance by overriding its toString. Which is what I want, the full output of the error.

In the other test case, I used chai-as-promised like so: expect(thePromise).to.eventually.be.fulfilled. In this case what I get is the type of output shown in the original issue description.

@domenic
Copy link
Collaborator

domenic commented Aug 5, 2016

I'm rolling up all bugs in the category "isRejected/rejectedWith doesn't behave like Chai's error rejectors" into #166.

@domenic domenic closed this as completed Aug 5, 2016
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

No branches or pull requests

4 participants