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

rejectedWith not reading constructor names #64

Closed
OliverJAsh opened this issue Jul 22, 2014 · 3 comments
Closed

rejectedWith not reading constructor names #64

OliverJAsh opened this issue Jul 22, 2014 · 3 comments
Labels

Comments

@OliverJAsh
Copy link

With plain Chai, if I do:

expect(function () {
    throw new Error();
}).to.throw(Array);

I get:

AssertionError: expected [Function] to throw 'Array' but 'Error' was thrown

With Chai as Promised, if I do the equivalent:

var d = Q.defer();
d.reject(new Error());
return expect(d.promise).to.eventually.be.rejectedWith(Array);

I get:

AssertionError: expected promise to be rejected with undefined but it was rejected with [Error]

Chai as Promised thinks that the Array constructor’s name is undefined.

I had a brief look into this: https://github.com/domenic/chai-as-promised/blob/d607a914ea8cff473f179becf8029a241ed011ee/lib/chai-as-promised.js#L152. Should we be reading the name property from the constructor function, instead of creating an instance and looking for a name on that? Alternatively the name could be read as instance.constructor.name. Here is what looks like the equivalent line but in Chai: https://github.com/chaijs/chai/blob/ab999d89171634e3b953765c6d0c8a7d454a4b59/lib/chai/core/assertions.js#L1054

Also, the error message format is slightly difference compared to standard Chai. Is this intentional, out of curiosity?

@OliverJAsh
Copy link
Author

I'm happy to raise a PR if you think I'm on the right tracks here…

@domenic
Copy link
Collaborator

domenic commented Jul 24, 2014

In general this seems like a special case of #47. I would prefer the solution outlined there (i.e., extract Chai's logic into a Chai util; release a new Chai version; depend on and use that logic). But a pull request for a small patch to make us match Chai's logic better would be OK too.

@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
lddubeau added a commit to lddubeau/chai-as-promised that referenced this issue Sep 18, 2016
lddubeau added a commit to lddubeau/chai-as-promised that referenced this issue Sep 18, 2016
We now use the check-error package to get the constructor name of the
error we expect to get with `rejectedWith`. For recent versions of Chai,
this makes `rejectedWith` consistent in behavior with Chai's `throw`.

Fixes chaijs#64.
domenic pushed a commit that referenced this issue Sep 27, 2016
domenic pushed a commit that referenced this issue Sep 27, 2016
We now use the check-error package to get the constructor name of the error we expect to get with `rejectedWith`. For recent versions of Chai, this makes `rejectedWith` consistent in behavior with Chai's `throw`.

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

No branches or pull requests

2 participants