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

chore(lint): use jest/prefer-to-have-length rule #13370

Merged
merged 3 commits into from
Oct 3, 2022
Merged

chore(lint): use jest/prefer-to-have-length rule #13370

merged 3 commits into from
Oct 3, 2022

Conversation

mrazauskas
Copy link
Contributor

Summary

Also jest/prefer-to-have-length rule could be added to ESLint config. Quick search shows that currently toHaveLength matcher is used 81 time in 36 files (excluding *.md). Let’s add few more?

Test plan

Green CI.

@@ -349,7 +349,7 @@ jest.mock('./sound-player', () => {
});
```

This will let us inspect usage of our mocked class, using `SoundPlayer.mock.calls`: `expect(SoundPlayer).toHaveBeenCalled();` or near-equivalent: `expect(SoundPlayer.mock.calls.length).toBe(1);`
This will let us inspect usage of our mocked class, using `SoundPlayer.mock.calls`: `expect(SoundPlayer).toHaveBeenCalled();` or near-equivalent: `expect(SoundPlayer.mock.calls.length).toBeGreaterThan(0);`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -167,6 +167,8 @@ module.exports = {
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
Copy link
Contributor Author

@mrazauskas mrazauskas Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jest/prefer-to-contain is added for completeness. It did not find any errors, but that is not yet enough to use extends: ['plugin:jest/style'].

Comment on lines -18 to +19
expect(importedFn.mock.calls.length).toBe(1);
expect(localFn.mock.calls.length).toBe(1);
expect(importedFn).toHaveBeenCalledTimes(1);
expect(localFn).toHaveBeenCalledTimes(1);
Copy link
Contributor Author

@mrazauskas mrazauskas Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were reworked manually (here and in other files).

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@SimenB SimenB merged commit 71044c0 into jestjs:main Oct 3, 2022
@mrazauskas mrazauskas deleted the lint-use-jest/prefer-to-have-length-rule branch October 3, 2022 13:51
@github-actions
Copy link

github-actions bot commented Nov 3, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants