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

test(ui): Remove useProject mocks, add lint rule #88574

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

scttcper
Copy link
Member

@scttcper scttcper commented Apr 2, 2025

Our app bootstrap process initializes ProjectsStore with all available projects, we can do the same in our tests.

Why avoid mocks

  • Changing hooks that have been mocked requires updating every test that has mocked that hook. It creates a tight relationship between hooks and random tests.
  • Mocked tests do not test how components and hooks actually work.

Our app bootstrap process initializes ProjectsStore with all available projects, we can do the same in our tests.

*Why avoid mocks*
- Changing hooks that have been mocked requires updating every test that has mocked that hook. It creates a tight relationship between hooks and random tests.
- Mocked tests do not test how components and hooks actually work.
@scttcper scttcper requested review from a team as code owners April 2, 2025 17:09
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 2, 2025
Copy link
Member

@malwilley malwilley left a comment

Choose a reason for hiding this comment

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

Much better this way!

{
selector:
"CallExpression[callee.object.name='jest'][callee.property.name='mock'][arguments.0.value='sentry/utils/useProjects']",
message:
Copy link
Member

Choose a reason for hiding this comment

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

Appreciate the eslint rule since I assume most of these are just because the person writing the test didn't know they could do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think a lot lately is cursor

@scttcper scttcper enabled auto-merge (squash) April 2, 2025 17:16
@scttcper scttcper merged commit e5a3450 into master Apr 2, 2025
42 checks passed
@scttcper scttcper deleted the scttcper/remove-project-mocks branch April 2, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants