I'm not sure how to go about this. I've watched a few tutorials but I can't grasp the concept. I want to implement Unit testing on this function - Help! please.
The function returns a joke from the API using the button and renders the joke in a h5 tag.
function Random() {
const [joke, setJoke] = useState()
const newJoke = () => {
fetch("http://api.icndb.com/jokes/random")
.then(result => result.json())
.then(result2 => {
console.log(result2)
setJoke(result2.value.joke)
})
.catch(error => {
console.log(error);
});
}
HTML (render):
<h5 class="card-title">{joke}</h5>
<button name="Randombtn" class="btn btn-primary" onClick={() => newJoke()}>click here for another chuckle</button>
I've looked into Jest but dont know how to apply it to this.
Aucun commentaire:
Enregistrer un commentaire