queries returned by render are not scoped
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, react
- Ambito
- frontend, testing-qa
Direzione di ricerca
Inizia esaminando come render restituisce le sue query e come within(container) associa le query. Riproduci quindi l’esempio fornito e verifica che le query di render cerchino solo nel container restituito, mentre screen possa continuare a cercare nell’intero documento. Le implicazioni di breaking-change e della release devono essere risolte prima dell’implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
@testing-library/reactversion: 14.1.2- Testing Framework and version: Jest 29.7
- DOM Environment: jsdom 20.0.3
Relevant code or config:
it('uses a consistent scope', () => {
const MyComponent = () => {
useEffect(() => {
const separateElement = document.createElement('div');
separateElement.textContent = 'hello';
document.body.append(separateElement);
return () => separateElement.remove();
}, []);
return (
<div>
<div>hello</div>
</div>
);
};
const { container, getByText } = render(<MyComponent />);
within(container).getByText('hello'); // passes
getByText('hello'); // fails (finds 2 elements)
});
What happened:
The first test (within(container).getByText('hello')) passes, and the second (getByText('hello')) fails:
Found multiple elements with the text: hello
Here are the matching elements:
Ignored nodes: comments, script, style
<div>
hello
</div>
Ignored nodes: comments, script, style
<div>
hello
</div>
Problem description:
The container and queries returned by render should be consistent with each other: the queries should search within the returned container by default, to avoid pollution from other tests and libraries which attach elements to other parts of the DOM. For users who need to check the wider document, they can continue to use screen.
It is also worth noting that the documentation claims that the queries are "bound", which does not match the current behaviour (since they apply globally across the document).
Suggested solution:
It is possible to make a wrapper function in user-space which works around this, which should be easy to integrate into the core library:
export const renderScoped = (ui: ReactElement, options?: RenderOptions) => {
const rendered = render(ui, options);
return {
...rendered,
...within(rendered.container),
};
};
This will be a potentially breaking change for users who currently rely on the queries not being scoped, so probably needs to be a "4.2" release.
- 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