Skip to content

Commit

Permalink
Use check-error to get expected constructor name
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lddubeau authored and domenic committed Sep 27, 2016
1 parent e425136 commit 1f7fc93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 12 additions & 5 deletions lib/chai-as-promised.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
/* istanbul ignore else */
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// NodeJS
module.exports = factory();
module.exports = factory(require("check-error"));
} else if (typeof define === "function" && define.amd) {
// AMD
define(factory);
define(["check-error"], factory);
} else {
/*global self: false */

// Other environment (usually <script> tag): plug in to global chai instance directly.
var chaiAsPromised = factory();
var chaiAsPromised = factory(self.checkError);
chai.use(chaiAsPromised);

// Expose as a property of the global object so that consumers can configure the `transferPromiseness` property.
self.chaiAsPromised = chaiAsPromised;
}
}(function () {
}(function (checkError) {
"use strict";

chaiAsPromised.transferPromiseness = function (assertion, promise) {
Expand All @@ -32,6 +32,13 @@
var Assertion = chai.Assertion;
var assert = chai.assert;

// If we are using a version of Chai that has checkError on it,
// we want to use that version to be consistent. Otherwise, we use
// what was passed to the factory.
if (utils.checkError) {
checkError = utils.checkError;
}

function isLegacyJQueryPromise(thenable) {
// jQuery promises are Promises/A+-compatible since 3.0.0. jQuery 3.0.0 is also the first version
// to define the catch method.
Expand Down Expand Up @@ -154,7 +161,7 @@
Constructor = null;
message = null;
} else if (typeof Constructor === "function") {
constructorName = (new Constructor()).name;
constructorName = checkError.getConstructorName(Constructor);
} else {
Constructor = null;
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
"cover": "istanbul cover node_modules/mocha/bin/_mocha && opener ./coverage/lcov-report/lib/chai-as-promised.js.html"
},
"peerDependencies": {
"chai": ">= 2.1.2 < 4"
"chai": ">= 2.1.2 < 4",
"check-error": "^1.0.2"
},
"devDependencies": {
"chai": "^3.0.0",
"coffee-script": "1.10.0",
"istanbul": "0.4.1",
"ecstatic": "^1.3.1",
"glob": "^6.0.1",
"istanbul": "0.4.1",
"jshint": "^2.8.0",
"mocha": "^2.3.4",
"opener": "^1.4.1",
Expand Down

0 comments on commit 1f7fc93

Please sign in to comment.