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

141
Vistas
How to test different types of test for a single render in React with testing-library?

I'm new in TDD for the React. I've decided to use the react-testing-library to start TDD for development. Suppose that, I should check a prop and simple text in component:

import { render, screen } from '@testing-library/react';
import Card from '../Card';

test('render without crash', () => {
  render(<Card />);
  expect(screen.getByText('Card Component')).toBeInTheDocument();
});

test('title', () => {
  render(<Card title="test" />);
  expect(screen.getByText('test')).toBeInTheDocument();
});

I used render two times two check different types of rendering for my component. But I was worry about performance... Is it best practice to separately use render in any tests? or I should create something like this common variable:

const Component = render(<Card title={...} prop2={} prop3={} ... />);

then use Component instead using render again?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't this this would be a bad practice. I usually use one of these approach :

  • render my component once in a beforeEach, and use it in multiple test(), if I always need the same setup for each test (props, contexts, redux store...),
  • render my component in each test(), so I can adjust props and context and test multiple configuration.

See https://stackoverflow.com/a/61838982/2295549 for a more complete explanation, and some pros/cons.

But using render multiple times is not a bad practice, in fact it is a pattern used in official docs.

about 4 years ago · Juan Pablo Isaza Denunciar
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