diff --git a/test/jest-mock-multiple-with-same-path.js b/test/jest-mock-multiple-with-same-path.js index 5f7df8c..d7142e1 100644 --- a/test/jest-mock-multiple-with-same-path.js +++ b/test/jest-mock-multiple-with-same-path.js @@ -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', @@ -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', + ], + }, ], }); diff --git a/test/jest-mock-without-import.js b/test/jest-mock-without-import.js index 2853eaf..cca0c92 100644 --- a/test/jest-mock-without-import.js +++ b/test/jest-mock-without-import.js @@ -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', }, @@ -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', }, @@ -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',