I want to test whenever i'm logged in with the text that is shown from Sweet alert. This what i've so far but given me a "Timed out in waitFor."
Why is not able to find "Je bent ingelogd"
async function onSubmit(data, e){
e.target.reset();
await axios({
method: 'post',
url: 'http://localhost:8080/user/signin?username='+ data.username +'&password=' + data.password,
headers: {
'Content-Type': 'application/json',
},
}).then(response => {
console.log(response);
localStorage.setItem('jwttoken', response.data);
loginModalToggle();
props.checkIfLoggedIn();
MySwal.fire({
// position: 'top-end',
icon: 'success',
title: "Je bent ingelogd",
showConfirmButton: false,
// timer: 1500,
backdrop: false,
})
}).catch(error => {
setError("Je gebruikersnaam en wachtwoord komen niet overeen op een account");
console.log(error)
});
}
describe('testing my Bootsrap material component...', () => {
it("Should check if user is logged in by get popup content text to exist", async () => {
render(<ModalLogin />)
// To open the Modal
fireEvent.click(screen.getByText("Login"))
// simulation of user is typing things there...
user.type(screen.getByLabelText("Your name"), "admin")
user.type(screen.getByLabelText("Your password"), "admin")
// click to submit
fireEvent.click(screen.getByText("Save changes"))
// get the response
await waitFor(() => screen.findByText('Je bent ingelogd'))
// expect(screen.findByText('Je bent ingelogd')).toBeDefined()
})
})
Aucun commentaire:
Enregistrer un commentaire