Saltar al contenido
Skillpedia
Pruebas40 mil · #7385

react18-enzyme-to-rtl

Qué hace

Esta herramienta te ayuda a actualizar los tests de tu código. Si usaste una herramienta antigua llamada Enzyme para probar tu código de React, te ayuda a cambiarte a una nueva llamada React Testing Library, que es más adecuada para React 18.

Cuándo usarla

  • ✓Cuando necesites actualizar tests antiguos de Enzyme para que funcionen con React 18.
  • ✓Cuando tus tests de Enzyme dejen de funcionar después de actualizar tu proyecto de React.
  • ✓Cuando quieras probar tu código de React centrándote en lo que ve y hace el usuario, y no en los detalles internos.

Link de la skill

https://github.com/github/awesome-copilot/blob/main/skills/react18-enzyme-to-rtl/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/github/awesome-copilot/blob/main/skills/react18-enzyme-to-rtl/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“¿Cómo convierto un test de Enzyme que comprueba el estado interno de un componente para que use React Testing Library?”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La herramienta relaciona las funciones antiguas de Enzyme con las nuevas funciones de React Testing Library. Te muestra cómo reescribir tus tests para centrarse en el comportamiento visible para el usuario, en lugar de mirar los detalles internos del código.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

React 18 Enzyme → RTL Migration

Enzyme has no React 18 adapter and no React 18 support path. All Enzyme tests must be rewritten using React Testing Library.

The Philosophy Shift (Read This First)

Enzyme tests implementation. RTL tests behavior.

// Enzyme: tests that the component has the right internal state
expect(wrapper.state('count')).toBe(3);
expect(wrapper.instance().handleClick).toBeDefined();
expect(wrapper.find('Button').prop('disabled')).toBe(true);

// RTL: tests what the user actually sees and can do
expect(screen.getByText('Count: 3')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /submit/i })).toBeDisabled();

This is not a 1:1 translation. Enzyme tests that verify internal state or instance methods don't have RTL equivalents - because RTL intentionally doesn't expose internals. Rewrite the test to assert the visible outcome instead.

API Map

For complete before/after code for each Enzyme API, read:

  • references/enzyme-api-map.md - full mapping: shallow, mount, find, simulate, prop, state, instance, configure
  • references/async-patterns.md - waitFor, findBy, act(), Apollo MockedProvider, loading states, error states

Core Rewrite Template

// Every Enzyme test rewrites to this shape:
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MyComponent from './MyComponent';

describe('MyComponent', () => {
  it('does the thing', async () => {
    // 1. Render (replaces shallow/mount)
    render(<MyComponent prop="value" />);

    // 2. Query (replaces wrapper.find())
    const button = screen.getByRole('button', { name: /submit/i });

    // 3. Interact (replaces simulate())
    await userEvent.setup().click(button);

    // 4. Assert on visible output (replaces wrapper.state() / wrapper.prop())
    expect(screen.getByText('Submitted!')).toBeInTheDocument();
  });
});

RTL Query Priority (use in this order)

  1. getByRole - matches accessible roles (button, textbox, heading, checkbox, etc.)
  2. getByLabelText - form fields linked to labels
  3. getByPlaceholderText - input placeholders
  4. getByText - visible text content
  5. getByDisplayValue - current value of input/select/textarea
  6. getByAltText - image alt text
  7. getByTitle - title attribute
  8. getByTestId - data-testid attribute (last resort)

Prefer getByRole over getByTestId. It tests accessibility too.

Wrapping with Providers

// Enzyme with context:
const wrapper = mount(
  <ApolloProvider client={client}>
    <ThemeProvider theme={theme}>
      <MyComponent />
    </ThemeProvider>
  </ApolloProvider>
);

// RTL equivalent (use your project's customRender or wrap inline):
import { render } from '@testing-library/react';
render(
  <MockedProvider mocks={mocks} addTypename={false}>
    <ThemeProvider theme={theme}>
      <MyComponent />
    </ThemeProvider>
  </MockedProvider>
);
// Or use the project's customRender helper if it wraps providers
Preguntas frecuentes

¿Por qué ya no puedo usar Enzyme?

Enzyme ya no se actualiza y no funciona bien con versiones recientes de React (como React 18). Ahora la herramienta recomendada es React Testing Library.

¿Qué significa 'probar el comportamiento' en lugar de 'probar la implementación'?

Probar la implementación (Enzyme) mira los detalles internos del código. Probar el comportamiento (React Testing Library) se centra en lo que el usuario final ve en la pantalla y en cómo interactúa con la aplicación.

¿Se pueden convertir directamente todos mis tests antiguos de Enzyme?

No exactamente. Como el enfoque es distinto (comportamiento frente a implementación), algunos tests antiguos que comprobaban detalles internos no tendrán una traducción directa. Tendrás que reescribirlos para comprobar el resultado visible.

Detalles

Descripción original del autor

Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow, mount, wrapper.find(), wrapper.simulate(), wrapper.prop(), wrapper.state(), wrapper.instance(), Enzyme configure/Adapter calls, or any test file that imports from enzyme. This skill covers the full API mapping and the philosophy shift from imp

repo: github/awesome-copilot

Popularidad

Estrellas en GitHub
40 mil
Posición en el ranking
#7385
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas