How to test functions inside functional component and also using hooks values
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Documentazione
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
Direzione di ricerca
L’esempio si trova in Employee.tsx e fa riferimento a useEmployeeDetails, useEmployeeData e useCleanData, ma non viene indicato alcun test del repository né alcun percorso sorgente. Inizia individuando questi hook e il componente Employee, quindi determina il comportamento visibile all’utente attivato dal pulsante di aggiornamento. Prima di poter definire l’ambito del lavoro sono necessari un risultato atteso concreto e la posizione del test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hello
I will try to explain the case in the simplest way that I could:
I have a component: Employee.tsx
It has a pseudo code like this:
const Employee = () => {
const { name, status } = useEmployeeDetails();
const { updateEmployeeInfo } = useEmployeeData(();
const { clearStorage} = useCleanData();
const generalUpdate = async() => {
await updateEmployeeInfo(name, status);
clearStorage();
}
return(
<>
<span>update</update>
<button onClick={generalUpdate}></button>
</>
)
}
I am trying to write a test for 'generalUpdate' function that contains async function (updateEmployeeInfo) that is using hooks data as parameters, also I want to have a way how to access or spy on this function to be able to manipulate it and test different scenarios.
So :
1- How to access a function inside a functional component.
2- how to mock this function, especially if it is using another async function in its implementation?
Basically testing a function that is using data from hooks (or using async function inside it) and it exists inside a functional component
I hope my explanation is clear 😄
- 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
-
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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
openai/codex-plugin-cc#813 ·
-
area: ops type: test
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
accensa/x402-facilitator-stellar#559 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
bilawalsidhu/gods-eye-view#1060 ·
I maintainer di solito rispondono entro 1 giorno
-
Progress difficulty filter lists Hard before MediumForse già presa @Pandamachi l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sysprog21/codetrial#281 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno