@@ -228,8 +228,8 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
228
228
});
229
229
` ,
230
230
output : dedent `
231
- import { pending } from 'actions';
232
231
import { describe, test } from '@jest/globals';
232
+ import { pending } from 'actions';
233
233
describe('foo', () => {
234
234
test.each(['hello', 'world'])("%s", (a) => {});
235
235
});
@@ -304,11 +304,11 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
304
304
` ,
305
305
// todo: this shouldn't be indenting the "test"
306
306
output : dedent `
307
+ const { expect, test } = require('@jest/globals');
307
308
const source = 'globals';
308
309
const {describe} = require(\`@jest/\${source}\`);
309
310
describe("suite", () => {
310
- const { expect, test } = require('@jest/globals');
311
- test("foo");
311
+ test("foo");
312
312
expect(true).toBeDefined();
313
313
})
314
314
` ,
@@ -407,8 +407,8 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
407
407
});
408
408
` ,
409
409
output : dedent `
410
- const { pending } = require('actions');
411
410
const { describe, test } = require('@jest/globals');
411
+ const { pending } = require('actions');
412
412
describe('foo', () => {
413
413
test.each(['hello', 'world'])("%s", (a) => {});
414
414
});
@@ -546,6 +546,61 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
546
546
} ,
547
547
] ,
548
548
} ,
549
+ {
550
+ code : dedent `
551
+ console.log('hello');
552
+ const onClick = jest.fn();
553
+ describe("suite", () => {
554
+ test("foo");
555
+ expect(onClick).toHaveBeenCalled();
556
+ })
557
+ ` ,
558
+ output : dedent `
559
+ const { describe, expect, jest, test } = require('@jest/globals');
560
+ console.log('hello');
561
+ const onClick = jest.fn();
562
+ describe("suite", () => {
563
+ test("foo");
564
+ expect(onClick).toHaveBeenCalled();
565
+ })
566
+ ` ,
567
+ errors : [
568
+ {
569
+ endColumn : 21 ,
570
+ column : 17 ,
571
+ line : 2 ,
572
+ messageId : 'preferImportingJestGlobal' ,
573
+ } ,
574
+ ] ,
575
+ } ,
576
+ {
577
+ code : dedent `
578
+ console.log('hello');
579
+ const onClick = jest.fn();
580
+ describe("suite", () => {
581
+ test("foo");
582
+ expect(onClick).toHaveBeenCalled();
583
+ })
584
+ ` ,
585
+ output : dedent `
586
+ import { describe, expect, jest, test } from '@jest/globals';
587
+ console.log('hello');
588
+ const onClick = jest.fn();
589
+ describe("suite", () => {
590
+ test("foo");
591
+ expect(onClick).toHaveBeenCalled();
592
+ })
593
+ ` ,
594
+ parserOptions : { sourceType : 'module' } ,
595
+ errors : [
596
+ {
597
+ endColumn : 21 ,
598
+ column : 17 ,
599
+ line : 2 ,
600
+ messageId : 'preferImportingJestGlobal' ,
601
+ } ,
602
+ ] ,
603
+ } ,
549
604
] ,
550
605
} ) ;
551
606
0 commit comments