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

126
Vistas
Next JS Unit test page with multiple components inside using jest

I'm trying to do unit testing for the first time. I want to test my index.tsx page with multiple components inside. My index.tsx page structure is like this

index.tsx

return (
  <div>
    <DefaultLayout
      meta={
        <Meta
          title=""
          description=""
          canonical="https://www.com"
        />
      }
    >
      {!props.acceptCookie && <CookieConsent />}
      <Header promo={props.promo} />
      <HomeBody
        totalPostsToday={props.totalPostsToday}
        promo={props.promo}
        postData={props}
        partners={props.partners}
      />
      <Footer />
    </DefaultLayout>
  </div>
)

If I run my test code I got an error says

Uncaught [Error: Objects are not valid as a React child (found: object with keys {store, .... If you meant to render a collection of children, use an array instead.

index.spec.tsx

import { act, render } from '@testing-library/react'
import { RouterContext } from 'next/dist/shared/lib/router-context'

import Index from '@/pages'
import { createMockRouter } from '@/test-utils/createMockRouter'
import { renderWithProviders } from '@/test-utils/reduxMockProvider'

describe('Index page', () => {
  test('should proper render components', async () => {
    await act(() => {
      render(
        <RouterContext.Provider value={createMockRouter({})}>
          {renderWithProviders(<Index />)}
        </RouterContext.Provider>
      )
    })
  })
})

Aside of my error, does my approach fine or is it better if I do isolation test per components?

about 4 years ago · Santiago Trujillo
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