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

AssertionError: expected [Function] to throw 'Error: baseURI option is required' but 'Error: baseURI option is required' was thrown #559

Closed
niftylettuce opened this issue Nov 27, 2015 · 4 comments

Comments

@niftylettuce
Copy link

1) should throw an error if we fail to pass baseURI:
     AssertionError: expected [Function] to throw 'Error: baseURI option is required' but 'Error: baseURI option is required' was thrown
  it('should throw an error if we fail to pass baseURI', () => {
    expect(() => {
      let api = new API();
    }).to.throw(new Error('baseURI option is required'));
  });

and this doesn't work either

  it('should throw an error if we fail to pass baseURI', () => {
    expect(new API).to.throw(new Error('baseURI option is required'));
  });
@niftylettuce
Copy link
Author

other relevant snippet:

export default class Api {

  constructor(opts) {

    this.opts = opts || {};

    if (!this.opts.baseURI)
      throw new Error('baseURI option is required');

@niftylettuce
Copy link
Author

also tested this:

expect(new API).to.throw('baseURI option is required');

doesn't work either

I'm also using dirty-chai

test/support/index.js: (this gets required in `mocha.opts)

// setup global chai methods
import chai from 'chai';
import dirtyChai from 'dirty-chai';
chai.config.includeStack = true;
chai.config.showDiff = true;
chai.use(dirtyChai);
global.AssertionError = chai.AssertionError;
global.Assertion = chai.Assertion;
global.expect = chai.expect;
global.assert = chai.assert;

@niftylettuce
Copy link
Author

See #551

@lucasfcosta
Copy link
Member

lucasfcosta commented Jun 24, 2016

Since we've got #683 merged, this one has been solved.
You can read more about our decisions on this matter reading this post, and the previous one.
But basically this is related to the behavior when using an Error for the check. When doing this, Chai does a strict (===) comparison to check if both instances are the same.

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