|
| 1 | +import * as nodeTest from 'node:test'; |
| 2 | +import { RuleTester } from '@typescript-eslint/rule-tester'; |
| 3 | +import { rule } from './no_empty_catch.js'; |
| 4 | + |
| 5 | +RuleTester.afterAll = nodeTest.after; |
| 6 | +// See https://typescript-eslint.io/packages/rule-tester/#with-specific-frameworks |
| 7 | +// Node test runner methods return promises which are not relevant in the context of testing. |
| 8 | +// We do ignore them in other places with void keyword. |
| 9 | +// eslint-disable-next-line @typescript-eslint/no-misused-promises |
| 10 | +RuleTester.it = nodeTest.it; |
| 11 | +// eslint-disable-next-line @typescript-eslint/no-misused-promises |
| 12 | +RuleTester.describe = nodeTest.describe; |
| 13 | + |
| 14 | +const ruleTester = new RuleTester(); |
| 15 | + |
| 16 | +ruleTester.run('no-empty-catch', rule, { |
| 17 | + valid: [ |
| 18 | + 'try {} catch (e) { console.log(e); }', |
| 19 | + 'try {} catch (e) { \n /* some comment*/ \n console.log(e); }', |
| 20 | + 'try {} catch (e) { \n // some comment \n console.log(e); }', |
| 21 | + ], |
| 22 | + invalid: [ |
| 23 | + { |
| 24 | + code: 'try {} catch (e) { /* some comment */ }', |
| 25 | + errors: [ |
| 26 | + { |
| 27 | + messageId: 'noEmptyCatch', |
| 28 | + }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + { |
| 32 | + code: 'try {} catch (e) { \n // some comment \n }', |
| 33 | + errors: [ |
| 34 | + { |
| 35 | + messageId: 'noEmptyCatch', |
| 36 | + }, |
| 37 | + ], |
| 38 | + }, |
| 39 | + { |
| 40 | + code: 'try {} catch (e) { }', |
| 41 | + errors: [ |
| 42 | + { |
| 43 | + messageId: 'noEmptyCatch', |
| 44 | + }, |
| 45 | + ], |
| 46 | + }, |
| 47 | + ], |
| 48 | +}); |
0 commit comments