Skip to content

Commit cf6fec2

Browse files
fix(prefer-importing-jest-globals): include valid tests
1 parent 7fb370b commit cf6fec2

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

src/rules/__tests__/prefer-importing-jest-globals.test.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,73 @@ import { FlatCompatRuleTester as RuleTester } from './test-utils';
55
new RuleTester({
66
parser: require.resolve('@typescript-eslint/parser'),
77
}).run('prefer-importing-jest-globals: typescript edition', rule, {
8-
valid: [],
8+
valid: [
9+
{
10+
code: dedent`
11+
// with import
12+
import { test, expect } from '@jest/globals';
13+
test('should pass', () => {
14+
expect(true).toBeDefined();
15+
});
16+
`,
17+
parserOptions: { sourceType: 'module' },
18+
},
19+
{
20+
code: dedent`
21+
test('should pass', () => {
22+
expect(true).toBeDefined();
23+
});
24+
`,
25+
options: [{ types: ['jest'] }],
26+
parserOptions: { sourceType: 'module' },
27+
},
28+
{
29+
code: dedent`
30+
const { it } = require('@jest/globals');
31+
it('should pass', () => {
32+
expect(true).toBeDefined();
33+
});
34+
`,
35+
options: [{ types: ['test'] }],
36+
parserOptions: { sourceType: 'module' },
37+
},
38+
{
39+
code: dedent`
40+
// with require
41+
const { test, expect } = require('@jest/globals');
42+
test('should pass', () => {
43+
expect(true).toBeDefined();
44+
});
45+
`,
46+
},
47+
{
48+
code: dedent`
49+
const { test, expect } = require(\`@jest/globals\`);
50+
test('should pass', () => {
51+
expect(true).toBeDefined();
52+
});
53+
`,
54+
},
55+
{
56+
code: dedent`
57+
import { it as itChecks } from '@jest/globals';
58+
itChecks("foo");
59+
`,
60+
parserOptions: { sourceType: 'module' },
61+
},
62+
{
63+
code: dedent`
64+
const { test } = require('@jest/globals');
65+
test("foo");
66+
`,
67+
},
68+
{
69+
code: dedent`
70+
const { test } = require('my-test-library');
71+
test("foo");
72+
`,
73+
},
74+
],
975
invalid: [
1076
{
1177
code: dedent`

0 commit comments

Comments
 (0)