I have a Seo component that uses the next/head component. I would like to test this Seo component, but mocking next/head seems to do nothing at all. Am I doing something wrong?
import TestRenderer from 'react-test-renderer';
import Seo from '../Seo';
jest.mock(
"next/head",
() => function Head({ children }) {
return children;
},
);
it('should display seo', () => {
const render = TestRenderer.create(
<Seo />,
);
expect(render.toJSON()).toMatchSnapshot();
});
import Head from "next/head";
function Seo() {
return (
<Head>
<title>Title SEO</title>
</Head>
);
}
2
Answers
This works for me (remove typescript if just using js)
I’m not sure if the test should be delayed to wait for the DOM manipulation to end. Also
document.head
might be needed to be provided as acontainer
.