From c154bae98e6a88b1056ee3d6faf0588c055d9cc3 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 7 Mar 2021 09:25:17 +1300 Subject: [PATCH] fix(unbound-method): only swollow `MODULE_NOT_FOUND` errors --- src/rules/__tests__/unbound-method.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rules/__tests__/unbound-method.test.ts b/src/rules/__tests__/unbound-method.test.ts index 481bdd3a1..7dd92b091 100644 --- a/src/rules/__tests__/unbound-method.test.ts +++ b/src/rules/__tests__/unbound-method.test.ts @@ -124,13 +124,28 @@ const TSESLintPluginRef: { throwWhenRequiring: boolean } = { jest.mock('@typescript-eslint/eslint-plugin', () => { if (TSESLintPluginRef.throwWhenRequiring) { - throw new Error('oh noes!'); + throw new (class extends Error { + public code = 'MODULE_NOT_FOUND'; + })(); } return jest.requireActual('@typescript-eslint/eslint-plugin'); }); describe('error handling', () => { + describe('when an error is thrown accessing the base rule', () => { + it('re-throws the error', () => { + jest.mock('@typescript-eslint/eslint-plugin', () => { + throw new Error('oh noes!'); + }); + + jest.resetModuleRegistry(); + + // eslint-disable-next-line @typescript-eslint/no-require-imports,node/no-missing-require + expect(() => require('../unbound-method').default).toThrow(/oh noes!/iu); + }); + }); + describe('when @typescript-eslint/eslint-plugin is not available', () => { const ruleTester = new ESLintUtils.RuleTester({ parser: '@typescript-eslint/parser',