Support for React.cache function
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- javascript, node.js, react
- Área
- frontend, testing-qa
Línea de trabajo
Comienza ejecutando la reproducción proporcionada de testCached.tsx, TestComponent.tsx y TestPage.tsx con React, Node 20 o 22, Vitest o Jest y jsdom. Comprueba los límites de compatibilidad de package.json y determina después si React.cache puede admitirse en este entorno de pruebas o si es necesario documentar instrucciones de mocking; el trabajo estará terminado cuando la reproducción pase o la limitación esté documentada claramente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
@testing-library/reactversion: 16.3.0- Testing Framework and version: Tested in
[email protected]and[email protected] - DOM Environment:
[email protected] - Node 20 or 22
Relevant code or config:
// testCached.tsx
import { cache } from 'react';
export default cache((data: number) => {
return Math.random() * data;
});
----------------------------------------------------------------------
// TestComponent.tsx
import myCachedFunction from "./testCached";
import React from "react";
export const TestComponent = () => {
return (
<div>
<p data-testid="cached-value-component">{myCachedFunction(200)}</p>
</div>
);
};
----------------------------------------------------------------------
// TestPage.tsx
import { TestComponent } from "./TestComponent";
import myCachedFunction from "./testCached";
import React from "react";
export function TestPage() {
return (
<div>
<p data-testid="cached-value-page">{myCachedFunction(200)}</p>
<TestComponent />
</div>
);
}
----------------------------------------------------------------------
// Testfile
it("Should use the cached value", () => {
render(<TestPage />);
expect(screen.getByTestId("cached-value-page").textContent).toEqual(
screen.getByTestId("cached-value-component").textContent
);
});
What you did:
We are using the React.cache function but cannot get it to work in tests.
What happened:
In tests, it does not use the cache but simply returns a new value for each call. When running the above code in nextjs 14 it works as expected and returns the cached value instead of a new value displaying the same value in TestComponent and TestPage.
For example the tests return:
Expected: "158.69893572775896"
Received: "45.853220887195164"
Also worth mentioning i experimented with different solutions, for example some in this issue, but ended up having it mocked.
Reproduction:
Problem description:
Suggested solution:
It should work as expected, or at least mention in docs to mock it
- Lenguaje dominante
- JavaScript
- Estrellas
- 19.7k
- Forks
- 1.2k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de testing-library/react-testing-library
-
fireEvent.select does not wrap its automatic native focus in actPosiblemente ocupada @sergioperezcheco la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict modeQuizá libre de nuevo @suhailopensource la tomó hace 73 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
testing-library/react-testing-library#1466 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
testing-library/react-testing-library#1459 · 2 comentarios ·
-
perf: optimize container lookup with early exitQuizá libre de nuevo @Ch-Abhinav-Chowdary la tomó hace 299 días y no hay ningún pull request abierto. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 35/100
testing-library/react-testing-library#1430 · 1 comentario ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Posiblemente ocupada @swarnim02 la tomó hace 317 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
Todos los issues de testing-library/react-testing-library
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
druxt/umami.demo.druxtjs.org#527 ·
Los mantenedores suelen responder en 9 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
NuSkooler/enigma-bbs#907 ·
Los mantenedores suelen responder en 1 día
-
documentation good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
documentation good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día