-
Notifications
You must be signed in to change notification settings - Fork 108
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
rejectedWith / check-error doesn't compare the real prototype #226
Comments
In general Chai as Promised's Otherwise you can just check the rejection value: const rejectionErr = await promise.catch(err => err);
expect(rejectionError).to.equal(httpError); |
Your suggested solution unfortunately doesn't work for me. It still says:
But if I see it right, the check for this is done here: |
Sorry, I had an extra |
Still doesn't work. Mhm, seems like I do something wrong. |
@janis91 As Domenic mentioned, Your original example is failing because, when passed an This should work: await expect(Promise.reject(new HttpError(404, 'Not found.')))
.to.be.rejectedWith(HttpError, 'Not found.')
.and.eventually.have.property('statusCode', 404); (I personally think it'd be more useful for |
@meeber thanks for your response. Your approach works fine. I will raise this issue on chai as well and let you know the issue number here. I think for now I will stick to your suggestion, but in the future it would be quite useful to be able to check for a deep equality of errors. Especially because the world is moving forward and more and more projects are written with es6 and use classes and extend the Error class in order to have a nicer error handling available. |
Hi,
I have an issue with rejectedWith and I guess it is caused by the check-error dependency under the hood:
I am using Error to extend it and define an own Error (here HttpError) like so:
Now I have an async function that is throwing an instance of HttpError (that is created inside the function, therefore I create two new HttpErrors in the example below) and test it with rejectedWith():
I would have expected this works, but it does not and gives back the following error:
My expectation would be that it compares if the thrown error deepEquals an object given, but it doesn't. It uses the check-error compatibleInstance check and this doesn't include a differentiation between different errors (and custom properties inside of it). The problem is obviously the
instanceof Error
as the HttpError extends Error it is still a instanceof Error.Do you have a suggestion how to deal with this?
The text was updated successfully, but these errors were encountered: