Skip to content

Commit

Permalink
chore(require-hook): misc updates (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Oct 17, 2021
1 parent ce8cd61 commit 778bd21
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/require-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ directly within the body of a `describe`, _except_ for the following:
- `import` statements
- `const` variables
- `let` _declarations_, and initializations to `null` or `undefined`
- Classes
- Types
- Calls to the standard Jest globals

Expand Down
69 changes: 69 additions & 0 deletions src/rules/__tests__/require-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ ruleTester.run('require-hook', rule, {
expect(myFn()).toBe(1);
});
`,
{
code: dedent`
import { myFn } from '../functions';
test('myFn', () => {
expect(myFn()).toBe(1);
});
`,
parserOptions: { sourceType: 'module' },
},
dedent`
class MockLogger {
log() {}
}
test('myFn', () => {
expect(myFn()).toBe(1);
});
`,
dedent`
const { myFn } = require('../functions');
Expand Down Expand Up @@ -357,3 +376,53 @@ ruleTester.run('require-hook', rule, {
},
],
});

new TSESLint.RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
}).run('require-hook: typescript edition', rule, {
valid: [
dedent`
import { myFn } from '../functions';
// todo: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56545
declare module 'eslint' {
namespace ESLint {
interface LintResult {
fatalErrorCount: number;
}
}
}
test('myFn', () => {
expect(myFn()).toBe(1);
});
`,
],
invalid: [
{
code: dedent`
import { setup } from '../test-utils';
// todo: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56545
declare module 'eslint' {
namespace ESLint {
interface LintResult {
fatalErrorCount: number;
}
}
}
describe('some tests', () => {
setup();
});
`,
errors: [
{
messageId: 'useHook',
line: 13,
column: 3,
},
],
},
],
});

0 comments on commit 778bd21

Please sign in to comment.