0

In our tests, we had several snapshots that included content wrapped in next/head. We had previously followed the below pattern for the mock, which allowed us to see all the header tags like meta, link, title, etc in the snapshot for the component being tested.

jest.mock('next/head', () => {
 return {
 __esModule: true,
 default: ({ children }: { children: Array<ReactElement> }) => {
 return children
 }
 }
})

However, after upgrading, we see these tests fail and all the header-specific fields like meta, link, etc are all absent from the component fragment. We were testing the snapshot like the below.

const { container } = render()
expect(container).toMatchSnapshot()

No matter how we update the mock, we're unable to get the header tags to appear in the component fragment snapshot.

Drew Reese
207k20 gold badges285 silver badges294 bronze badges
asked Nov 10, 2025 at 14:22

1 Answer 1

0

It turns out that in React 19, header components are automatically hoisted to the header itself. Accordingly, we had to update the the tests to do a diff of the header as well like the below.

const { container } = render()
expect(container).toMatchSnapshot()
expect(document.head).toMatchSnapshot('headers')
answered Nov 10, 2025 at 14:22
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.