Skip to content

Commit

Permalink
fix(prefer-importing-jest-globals): include valid tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimmer-atlassian committed Aug 22, 2024
1 parent 60812f4 commit 4f6cf0a
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/rules/__tests__/prefer-importing-jest-globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,73 @@ import { FlatCompatRuleTester as RuleTester } from './test-utils';
new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
}).run('prefer-importing-jest-globals: typescript edition', rule, {
valid: [],
valid: [
{
code: dedent`
// with import
import { test, expect } from '@jest/globals';
test('should pass', () => {
expect(true).toBeDefined();
});
`,
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
test('should pass', () => {
expect(true).toBeDefined();
});
`,
options: [{ types: ['jest'] }],
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
const { it } = require('@jest/globals');
it('should pass', () => {
expect(true).toBeDefined();
});
`,
options: [{ types: ['test'] }],
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
// with require
const { test, expect } = require('@jest/globals');
test('should pass', () => {
expect(true).toBeDefined();
});
`,
},
{
code: dedent`
const { test, expect } = require(\`@jest/globals\`);
test('should pass', () => {
expect(true).toBeDefined();
});
`,
},
{
code: dedent`
import { it as itChecks } from '@jest/globals';
itChecks("foo");
`,
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
const { test } = require('@jest/globals');
test("foo");
`,
},
{
code: dedent`
const { test } = require('my-test-library');
test("foo");
`,
},
],
invalid: [
{
code: dedent`
Expand Down

0 comments on commit 4f6cf0a

Please sign in to comment.