Skip to content

Commit

Permalink
Replace get-func-name with Function.prototype.name (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Oct 8, 2021
1 parent 6ff6a00 commit e355b1a
Show file tree
Hide file tree
Showing 3 changed files with 1,620 additions and 1,821 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import getFunctionName from 'get-func-name';

/**
* ### .compatibleInstance(thrown, errorLike)
*
Expand Down Expand Up @@ -85,14 +83,14 @@ function compatibleMessage(thrown, errMatcher) {
function getConstructorName(errorLike) {
let constructorName = errorLike;
if (errorLike instanceof Error) {
constructorName = getFunctionName(errorLike.constructor);
constructorName = errorLike.constructor.name;
} else if (typeof errorLike === 'function') {
// If `err` is not an instance of Error it is an error constructor itself or another function.
// If we've got a common function we get its name, otherwise we may need to create a new instance
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
constructorName = getFunctionName(errorLike);
constructorName = errorLike.name;
if (constructorName === '') {
const newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
const newConstructorName = (new errorLike().name); // eslint-disable-line new-cap
constructorName = newConstructorName || constructorName;
}
}
Expand Down
Loading

0 comments on commit e355b1a

Please sign in to comment.