Skip to content

Commit 778bd21

Browse files
authored
chore(require-hook): misc updates (#960)
1 parent ce8cd61 commit 778bd21

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

docs/rules/require-hook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ directly within the body of a `describe`, _except_ for the following:
2020
- `import` statements
2121
- `const` variables
2222
- `let` _declarations_, and initializations to `null` or `undefined`
23+
- Classes
2324
- Types
2425
- Calls to the standard Jest globals
2526

src/rules/__tests__/require-hook.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ ruleTester.run('require-hook', rule, {
3232
expect(myFn()).toBe(1);
3333
});
3434
`,
35+
{
36+
code: dedent`
37+
import { myFn } from '../functions';
38+
39+
test('myFn', () => {
40+
expect(myFn()).toBe(1);
41+
});
42+
`,
43+
parserOptions: { sourceType: 'module' },
44+
},
45+
dedent`
46+
class MockLogger {
47+
log() {}
48+
}
49+
50+
test('myFn', () => {
51+
expect(myFn()).toBe(1);
52+
});
53+
`,
3554
dedent`
3655
const { myFn } = require('../functions');
3756
@@ -357,3 +376,53 @@ ruleTester.run('require-hook', rule, {
357376
},
358377
],
359378
});
379+
380+
new TSESLint.RuleTester({
381+
parser: require.resolve('@typescript-eslint/parser'),
382+
}).run('require-hook: typescript edition', rule, {
383+
valid: [
384+
dedent`
385+
import { myFn } from '../functions';
386+
387+
// todo: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56545
388+
declare module 'eslint' {
389+
namespace ESLint {
390+
interface LintResult {
391+
fatalErrorCount: number;
392+
}
393+
}
394+
}
395+
396+
test('myFn', () => {
397+
expect(myFn()).toBe(1);
398+
});
399+
`,
400+
],
401+
invalid: [
402+
{
403+
code: dedent`
404+
import { setup } from '../test-utils';
405+
406+
// todo: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56545
407+
declare module 'eslint' {
408+
namespace ESLint {
409+
interface LintResult {
410+
fatalErrorCount: number;
411+
}
412+
}
413+
}
414+
415+
describe('some tests', () => {
416+
setup();
417+
});
418+
`,
419+
errors: [
420+
{
421+
messageId: 'useHook',
422+
line: 13,
423+
column: 3,
424+
},
425+
],
426+
},
427+
],
428+
});

0 commit comments

Comments
 (0)