Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weary-pilgrim opened this issue May 9, 2024 · 1 comment
Open

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

weary-pilgrim opened this issue May 9, 2024 · 1 comment
Labels

Comments

@weary-pilgrim
Copy link

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');
@G-Rath
Copy link
Collaborator

G-Rath commented May 10, 2024

I think this is technically a duplicate of #1346 but your writeup is a lot clearer so will close the other one 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants