Skip to content

New rule to validate path given to jest.mock #1584

Open
@weary-pilgrim

Description

@weary-pilgrim

It would be really useful to have a lint rule that tells you when the path supplied to jest.mock does not exist. I would envision the rule working like this:

Disallow mocking of module paths that do not exist

When using jest.mock and jest.doMock, the path supplied must be an module or local file that exists.

Rule details

This rule triggers an error if the path supplied to jest.mock or jest.doMock does not exist.

The following patterns are considered errors:

// Module that cannot be found
jest.mock('some-module-not-in-package-json');

// Local file that cannot be found
jest.mock('../../this/path/does/not/exist');

The following patterns not considered errors:

// Module that can be found
jest.mock('some-module-in-package-json');

// Local file that can be found
jest.mock('../../this/path/really/does/exist');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions