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 does not work with custom error #159

Closed
maiertech opened this issue Jun 30, 2016 · 2 comments
Closed

rejectedWith does not work with custom error #159

maiertech opened this issue Jun 30, 2016 · 2 comments

Comments

@maiertech
Copy link

I am on Node 6.2.1 and use ES2015 syntax (whatever is supported). I'm writing a CLI tool and I have two occasions where I reject a promise with a custom error (with different messages):

reject(new NoMatchingFilesError('No matching tweet files in directory.'));

with NoMatchingFilesError being defined as

class NoMatchingFilesError extends Error {
  constructor(message) {
    super(message);
    this.name = this.constructor.name;
    this.message = message;
    Error.captureStackTrace(this, this.constructor.name);
  }
}

There are 2 corresponding unit tests that look like this (different messages):

it('should reject promise with NoMatchingFilesError', () => evaluation.getSinceId({
  list: 'dummy',
  user: 'dummy',
}).should.be.rejectedWith(NoMatchingFilesError, 'No matching tweet files in directory.'));

When I run the tests the first test fails and the second test passes.

I tracked the issue down to this line: https://github.com/domenic/chai-as-promised/blob/master/lib/chai-as-promised.js#L192. The test fails because reason instanceof Constructor evaluates to false for the first test. The second one evaluates to true.

In node-debug I see no difference: In both cases the Constructor looks fine and the prototype chains looks fine, and yet one test fails. When I rewrite my code use Error instead of custom NoMatchingFilesError both tests pass.

Any idea what's going wrong here?

This might be related to #113.

@maiertech maiertech changed the title rejectWith for custom errors does not work rejectedWith for custom errors does not work Jun 30, 2016
@maiertech maiertech changed the title rejectedWith for custom errors does not work rejectedWith does not work with custom error Jun 30, 2016
@domenic
Copy link
Collaborator

domenic commented Jun 30, 2016

If you can produce a small, 10-20 line reproduction case I can run standalone with no dependencies, I can test this more easily.

@domenic
Copy link
Collaborator

domenic commented Aug 5, 2016

Closing due to lack of small repro case.

@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

2 participants