From 3741f0516d9eb1364b92b7d372a9d7e93d5700af Mon Sep 17 00:00:00 2001 From: laconbass Date: Wed, 15 Jan 2014 18:49:16 +0100 Subject: [PATCH] Avoid error instantiation if possible on assert.throws Given an error constructor as function, try to get the error name from its prototype or itself before relying on the old behaviour. Closes #220 Replaces [the old pull](https://github.com/chaijs/chai/pull/221) to avoid useless commits. --- lib/chai/core/assertions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index d08a4205c..d41a48c1c 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -1026,7 +1026,10 @@ module.exports = function (chai, _) { constructor = null; errMsg = null; } else if (typeof constructor === 'function') { - name = (new constructor()).name; + name = constructor.prototype.name || constructor.name; + if (name === 'Error' && constructor !== Error) { + name = (new constructor()).name; + } } else { constructor = null; }