From 4f6cf0a8e166c835565a893874bb50981042dd81 Mon Sep 17 00:00:00 2001 From: Erin Zimmer Date: Thu, 22 Aug 2024 12:05:30 +1000 Subject: [PATCH] fix(prefer-importing-jest-globals): include valid tests --- .../prefer-importing-jest-globals.test.ts | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/rules/__tests__/prefer-importing-jest-globals.test.ts b/src/rules/__tests__/prefer-importing-jest-globals.test.ts index cf8756004..0f16a1a84 100644 --- a/src/rules/__tests__/prefer-importing-jest-globals.test.ts +++ b/src/rules/__tests__/prefer-importing-jest-globals.test.ts @@ -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`