-
Notifications
You must be signed in to change notification settings - Fork 392
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
Fix issue where error reporting wrong instanceof #543
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/auth0/nextjs-auth0/7SxTE59cysaY4YZWGZF3pbbeAPRb |
@@ -149,13 +149,6 @@ | |||
} | |||
}, | |||
"preset": "ts-jest", | |||
"globals": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using same target as project (es5
) so I can have a regression test for this issue
@@ -8,6 +8,7 @@ import { HttpError } from 'http-errors'; | |||
export class AccessTokenError extends Error { | |||
public code: string; | |||
|
|||
/* istanbul ignore next */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { AccessTokenError, HandlerError } from '../../src/utils/errors'; | ||
|
||
describe('errors', () => { | ||
test('should be instance of themselves', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Believe it or not, this test will fail in TS with target: es5
without the Object.setPrototypeOf(this, ThisError.prototype);
workaround
Description
Using the
instanceof
operator against theAccessTokenError
constructor always returns false, even if the object that is being tested is actually an instance ofAccessTokenError
.This is an issue introduced in nextjs-auth0 v1.5.0 by microsoft/TypeScript#13965 when we downgraded the compilation target to
es5
to support IE11 in c248efe#diff-3ae20d611c1c7263a9c1bce0449291ebfea1c5d578b3fcdbb596353ad885db25R19Using the workaround here https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
References
fixes #535
Testing
Set the target for jest to be the same as the main binary, so I could add a test case for this regression.
Using target
es5
on jest meant I had to add a couple ofignore next
's to resolve an issue in istanbul (see gotwarlost/istanbul#690)Checklist
main