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

Remove jest/no-conditional-in-test rule #383

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Feb 6, 2025

I propose that we remove this rule. I would argue that adding logic to tests is not as harmful as the docs for this rule would indicate and in fact can be quite useful.

  • When mocking functions with overloads, it is necessary to add logic inside of the mock implementation to handle different arguments.
  • When testing a function that can be called multiple ways where the behavior is mostly the same between inputs aside from a few edge cases, using an if statement to highlight the difference can be useful.

@mcmire mcmire requested review from a team as code owners February 6, 2025 18:53
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

I propose that we remove this rule. I would argue that adding logic to
tests is not as harmful as the docs for this rule would indicate and in
fact can be quite useful.

- When mocking functions with overloads, it is necessary to add logic
  inside of the mock implementation to handle different arguments.
- When testing a function that can be called multiple ways where the
  behavior is mostly the same between inputs aside from a few edge
  cases, using an `if` statement to highlight the difference can be
  useful.
@mcmire mcmire force-pushed the remove-jest-no-conditional-in-tests branch from 79d3242 to cdbb0d7 Compare February 6, 2025 19:08
Copy link
Member

@Mrtenz Mrtenz left a comment

Choose a reason for hiding this comment

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

I agree. This rule seems to be too strict in Snaps as well.

@mcmire mcmire merged commit b8fdc1f into main Feb 19, 2025
22 checks passed
@mcmire mcmire deleted the remove-jest-no-conditional-in-tests branch February 19, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants