Calling render on a component that throws, results in 4 renders
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, react, typescript
Direzione di ricerca
Inizia con la riproduzione collegata in error-component.spec.tsx e error-component.tsx, quindi esegui il test con le versioni indicate di React, Jest e @testing-library/react. Traccia il percorso di rendering per determinare perché il componente che genera l'errore viene invocato ripetutamente; il problema è risolto quando il numero di rendering osservato viene spiegato e il comportamento previsto viene stabilito con un'adeguata copertura dei test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- @testing-library/react version: 14.2.2
- Testing Framework and version: jest 29.4.1
- DOM Environment: jest-environment-jsdom 29.4.1
- node: 20.11.1
- react: 18.2.0
Relevant code or config:
https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.tsx
error-component.tsx (just as an example, I know the return is unreachable):
export const ErrorComponent = () => {
// This logs four times, but it should log only once?
console.log('test error in component');
// When debugging this during a test, the debugger wil stop here five times. But we expect that it stops only once?
throw new Error('test error in component');
return <p>This is an error test component, which will throw an error</p>;
};
error-component.spec.tsx:
import { render } from '@testing-library/react';
import { ErrorComponent } from './error-component';
it('should throw', () => {
expect(() => render(<ErrorComponent />)).toThrow('test error in component');
});
What you did:
I was trying to test if a specific error was thrown in a component and used the render function from @testing-library/react.
What happened:
When debugging the component that is called in the render function, I found out that it seems to load 4/5 times.
Without throwing an error in the component that is being rendered, the component only loads once.
When calling the component that throws an error without the render function, the component only loads once.
Reproduction:
Reproduction repo can be found here: https://github.com/R-J-dev/example-error-render-issue/tree/main
It's a new setup created with: npx create-nx-workspace@latest (https://nx.dev/getting-started/intro)
The test: https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.spec.tsx
The component: https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.tsx
Problem description:
Not sure if this is normal behavior, but for me it's unexpected behavior and couldn't find why this is happening.
Also:
- Probably not good for test performance
- Mocking things once isn't possible, when testing if an error has thrown
Suggested solution:
It looks like that the problem is in the render function from @testing-library/react, but besides from that I have no clue yet.
- 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 4 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 74 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 300 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 318 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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
XRPLF/xrpl-dev-portal#4000 ·
I maintainer di solito rispondono entro 1 giorno
-
accessibility good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] Bubble chart series name is not XML-escaped in the embedded workbook (xl/tables/table1.xml)Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
-
Content:Learn needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
anoopcodehack/DevBoard#609 ·
I maintainer di solito rispondono entro 1 giorno