When I give valid credentials it is passed. But I want to test my login API in jest with invalid credential and expect the status code as 401. How to do that?
it('fails with invalid credentials', async () => {
const res = await axios.post('/rest/api/login', data);
console.log('Status:', response.status);
expect(response.status).toBe(401);
});
Getting the following error message
Request failed with status code 401
at createError (node_modules/axios/lib/core/createError.js:16:15)
at settle (node_modules/axios/lib/core/settle.js:18:12)
at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:191:11)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 4.285 s
Aucun commentaire:
Enregistrer un commentaire