I'm starting TDD studies and came across a function like this:
const fetchexample = callback => {
fetch('/token', {
method: 'POST',
body: 'user=teste'
}).then(res => res.json()).then(json => {
localStorage.setItem('token', json.access_token)
}).then(() => callback())
}
But my question is how would we test this function? Since it makes an asynchronous request and I have never worked with this type of test for this type of request? Would anyone have any examples about the subject or article?