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

Replace get-func-name with Function.prototype.name #24

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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