I have a custom Document which is copied from the document:
import Document, { Html, Head, Main, NextScript } from 'next/document'
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
render() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export default MyDocument
I tried to write test for it with the following below:
import { render } from '@testing-library/react';
import MyDocument from '../_document.page';
describe('<MyDocument />', () => {
it('should render without errors', async () => {
const documentProps = {} as any;
render(<MyDocument {...documentProps} />);
});
});
But I get an error:
TypeError: Cannot destructure property 'inAmpMode' of '(0 , _react).useContext(...)' as it is null.
6 | const documentProps = {} as any;
7 |
> 8 | render(<MyDocument {...documentProps} />);
| ^
9 | });
10 | });
What is the recommended way to test the custom document or how do I resolve this? Thank you.