Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

320
Vistas
How to test custom `Document` in Next.js?

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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda