Skip to content

Commit

Permalink
add additional testcase, fix factories in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Aug 10, 2024
1 parent ef0e0f3 commit 79365b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions test/jest-mock-multiple-with-same-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
jest.mock('some-absolute-path');
jest.mock('some-absolute-path');
jest.mock('some-absolute-path');`,

errors: [
'jest.mock(\'some-absolute-path\') is used more than once',
'jest.mock(\'some-absolute-path\') is used more than once',
Expand All @@ -75,12 +74,21 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
jest.mock('../path/to/file');
jest.mock('../path/to/file');
jest.mock('../path/to/file');`,

errors: [
'jest.mock(\'../path/to/file\') is used more than once',
'jest.mock(\'../path/to/file\') is used more than once',
'jest.mock(\'../path/to/file\') is used more than once',
],
},
{
name: 'jest.mock path twice, one of them with factory',
code: `import { something } from 'some-absolute-path';
jest.mock('some-absolute-path');
jest.mock('some-absolute-path', () => ({ someFn: jest.fn() }));`,
errors: [
'jest.mock(\'some-absolute-path\') is used more than once',
'jest.mock(\'some-absolute-path\') is used more than once',
],
},
],
});
10 changes: 5 additions & 5 deletions test/jest-mock-without-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
name: 'ignore pattern 2',
},
{
code: `jest.mock('some-path-to-ignore', () => { someFn: jest.fn() });`,
code: `jest.mock('some-path-to-ignore', () => ({ someFn: jest.fn() }));`,
options: [{ ignoreMockWithFactory: true }],
name: 'ignore absolute path with factory',
},
{
code: `jest.mock('../some/relative/path/to/ignore', () => { someFn: jest.fn() });`,
code: `jest.mock('../some/relative/path/to/ignore', () => ({ someFn: jest.fn() }));`,
options: [{ ignoreMockWithFactory: true }],
name: 'ignore relative path with factory',
},
Expand All @@ -119,7 +119,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
name: 'ignore relative path with factory object',
},
{
code: `jest.mock('some-path-to-ignore', () => { someFn: jest.fn()}, { virtual: true });`,
code: `jest.mock('some-path-to-ignore', () => ({ someFn: jest.fn()}), { virtual: true });`,
options: [{ ignoreVirtual: true }],
name: 'ignore absolute path with virtual',
},
Expand Down Expand Up @@ -163,12 +163,12 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
name: 'missing relative path with factory object without ignoreMockWithFactory',
},
{
code: `jest.mock('some-absolute-path', () => { someFn: jest.fn()}, { virtual: true });`,
code: `jest.mock('some-absolute-path', () => ({ someFn: jest.fn()}), { virtual: true });`,
errors: [ { message: 'jest.mock() path "some-absolute-path" is not imported'}],
name: 'missing absolute path with virtual',
},
{
code: `jest.mock('some-absolute-path', () => { someFn: jest.fn()}, { virtual: false });`,
code: `jest.mock('some-absolute-path', () => ({ someFn: jest.fn()}), { virtual: false });`,
options: [{ ignoreVirtual: true }],
errors: [ { message: 'jest.mock() path "some-absolute-path" is not imported'}],
name: 'missing absolute path with virtual: false and ignoreVirtual',
Expand Down

0 comments on commit 79365b0

Please sign in to comment.