Support for React.cache function
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, node.js, react
- Ambito
- frontend, testing-qa
Direzione di ricerca
Inizia eseguendo la riproduzione fornita di testCached.tsx, TestComponent.tsx e TestPage.tsx con React, Node 20 o 22, Vitest o Jest e jsdom. Controlla i limiti di supporto di package.json, quindi determina se React.cache può essere supportato in questo ambiente di test o se sono necessarie istruzioni documentate per il mocking; il lavoro è completato quando la riproduzione passa o la limitazione è chiaramente documentata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
@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
- Lingua principale
- JavaScript
- Stelle
- 19.7k
- Fork
- 1.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di testing-library/react-testing-library
-
fireEvent.select does not wrap its automatic native focus in actForse già presa @sergioperezcheco l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict modeForse di nuovo libera @suhailopensource l’ha presa 73 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
testing-library/react-testing-library#1466 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
testing-library/react-testing-library#1459 · 2 commenti ·
-
perf: optimize container lookup with early exitForse di nuovo libera @Ch-Abhinav-Chowdary l’ha presa 299 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 35/100
testing-library/react-testing-library#1430 · 1 commento ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Forse già presa @swarnim02 l’ha presa 316 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Tutte le issue di testing-library/react-testing-library
Issue simili
-
bug user-priority/P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
bug confirmed perf
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
videojs/video.js#9400 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
agent/scanner bug hive/hosted-available-lke648397-260827-5n31
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rescript-lang/rescript#8765 ·
I maintainer di solito rispondono entro 1 giorno
-
feedback simulation workshop
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
githubnext/gh-aw-workshop#4417 ·
I maintainer di solito rispondono entro 1 giorno