Skip to content

fix(test): use forwardRef in gatsby Link mock to silence MUI ref warnings#442

Merged
jimmyandrade merged 1 commit into
mainfrom
fix/footer-gatsby-link-forwardref
Jul 16, 2026
Merged

fix(test): use forwardRef in gatsby Link mock to silence MUI ref warnings#442
jimmyandrade merged 1 commit into
mainfrom
fix/footer-gatsby-link-forwardref

Conversation

@jimmyandrade

Copy link
Copy Markdown
Member

Summary

  • Rewrites the Jest __mocks__/gatsby.js Link as a React.forwardRef component, matching production Gatsby Link, and stops destructuring ref from props.
  • Adds a Footer regression test asserting the Ajuda / Privacidade / Termos links render with the right href and that the MUI component / ref console warnings no longer fire.

Closes #441

Test plan

  • npm test — 28 suites green, snapshots unchanged
  • New regression test fails against the old mock, passes with the fix

Made with Cursor

…ings

MUI Link requires `component` to be a ref-capable element type. The Jest
mock for gatsby's Link was a plain function that also destructured `ref`
from props, triggering PropTypes and ref console warnings when rendering
Footer. Production gatsby Link already uses forwardRef; only the mock was
wrong. Adds a Footer regression test asserting the links render and the
warnings no longer fire.

Closes #441

Co-authored-by: Cursor <cursoragent@cursor.com>
@jimmyandrade jimmyandrade added the bug Something isn't working label Jul 16, 2026
@jimmyandrade jimmyandrade self-assigned this Jul 16, 2026
@jimmyandrade
jimmyandrade requested a review from Copilot July 16, 2026 16:22
@jimmyandrade
jimmyandrade merged commit 612e85e into main Jul 16, 2026
4 checks passed
@jimmyandrade
jimmyandrade deleted the fix/footer-gatsby-link-forwardref branch July 16, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes noisy MUI ref/PropTypes warnings in tests by updating the Jest Gatsby Link mock to be ref-capable (via React.forwardRef) and adds a regression test around Footer links to ensure the warnings don’t reappear.

Changes:

  • Update __mocks__/gatsby.js to export Link as a React.forwardRef component (instead of a plain mocked function) and stop treating ref as a normal prop.
  • Add a Footer regression test that asserts key footer links render with the expected href values and that ref-related console warnings are not emitted.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/Footer/index.test.js Adds RTL-based regression coverage for footer Gatsby links and absence of ref warnings.
__mocks__/gatsby.js Replaces the Gatsby Link test mock with a forwardRef implementation to match production behavior and satisfy MUI ref expectations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +26 to +47
const consoleError = jest
.spyOn(console, "error")
.mockImplementation(() => {})

const { getByText } = render(<Footer siteTitle="Test site title" />)

expect(getByText("Ajuda").closest("a")).toHaveAttribute("href", "/ajuda")
expect(getByText("Privacidade").closest("a")).toHaveAttribute(
"href",
"/privacidade"
)
expect(getByText("Termos de uso").closest("a")).toHaveAttribute(
"href",
"/termos"
)

const linkRefWarnings = consoleError.mock.calls.filter(
isFooterLinkRefWarning
)
expect(linkRefWarnings).toHaveLength(0)
consoleError.mockRestore()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Gatsby Link mock lacks forwardRef (Footer MUI Link warnings)

2 participants