Chai: Add support for Promise polyfill

Created on 19 Sep 2016  路  1Comment  路  Source: chaijs/chai

The following assertion will fail if Promises are not supported natively:

expect(result).to.be.a('promise');

Please consider adding support for using a Promise polyfill. Example:

chai.promise = PromisePolyfill;

The current workaround is to use an assertion like this:

expect(result).to.be.an.instanceof(PromisePolyfill);

Most helpful comment

Hey @natlibfi-arlehiko thanks for the issue.

I'll cut to the chase; I think we shouldn't do this, for a couple of reasons:

  1. Promise is a native type; so having some kind of variable to assign like this is a slippery slope (why not have this behaviour for all native types?). Do we have chai.object that can be reassigned? What about chai.array? chai.global?
  2. We already have this kind of support through another mechanism: Symbol.toStringTag. If your engine supports it (modern browsers or modern Node), and your promise polyfill supports it, then you can already make this assertion.

Because of these reasons, I'm going to close this issue. I would say that if you would like the behaviour you're requesting - you can raise an issue with the Promise polyfill you're using, for them to support Symbol.toStringTag.

Feel free to continue the discussion here too. Let me know your thoughts on the above, and if you have any other issues with chai please feel free to file them!

>All comments

Hey @natlibfi-arlehiko thanks for the issue.

I'll cut to the chase; I think we shouldn't do this, for a couple of reasons:

  1. Promise is a native type; so having some kind of variable to assign like this is a slippery slope (why not have this behaviour for all native types?). Do we have chai.object that can be reassigned? What about chai.array? chai.global?
  2. We already have this kind of support through another mechanism: Symbol.toStringTag. If your engine supports it (modern browsers or modern Node), and your promise polyfill supports it, then you can already make this assertion.

Because of these reasons, I'm going to close this issue. I would say that if you would like the behaviour you're requesting - you can raise an issue with the Promise polyfill you're using, for them to support Symbol.toStringTag.

Feel free to continue the discussion here too. Let me know your thoughts on the above, and if you have any other issues with chai please feel free to file them!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leifhanack picture leifhanack  路  4Comments

liborbus picture liborbus  路  4Comments

danthegoodman picture danthegoodman  路  3Comments

ghost picture ghost  路  4Comments

endymion00 picture endymion00  路  3Comments