Actually this code don't work, the error message is : thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
I an blocked since 1 week can someone help me ? When i call the route /login on postman its works perfectly
const session = require('express-session')
const res = require('express/lib/response')
const request = require('supertest')
const app = require("../routes/routes")
describe('test POST', () => {
it('login', async () => {
let result = await request(app)
.post('/login')
.send({
loginID:"1705",
loginPwd:"17051999"
})
})
})
I tried to increase the timeout but not works too
Here is the post route
app.post('/login', (req, res) => {
console.log(req.body)
let id = req.body.loginID
let mdp = req.body.loginPwd
if (id != '' && id != undefined) {
if (mdp != '' && mdp != undefined) {
let Login = require('../models/M_Login')
Login.testLogin(id,mdp, (result, id) => {
console.log(result)
switch (result.resultCode) {
case 0:
req.session.infoUser = result
req.session.infoUser.loginNo = id
req.session.success = 'Connexion réussie'
res.redirect('/accueil')
break
case 2001:
req.session.error = 'Identifiant inconnu'
res.redirect('/')
break
case 2002:
req.session.error = 'Mot de passe incorrect'
res.redirect('/')
break
case 1003:
req.session.error = 'Compte bloqué veuillez contacter l\'administrateur'
res.redirect('/')
break
}
})
} else {
req.session.error = 'Vous devez renseigner votre mot de passe'
res.redirect('/')
}
} else {
req.session.error = 'Vous devez renseigner votre identifiant'
res.redirect('/')
}
})
and here the function who call the API
const axios = require('axios').default;
const { baseUrlServer } = require('../server')
class M_Login {
static testLogin(id, mdp, cb) {
axios.post(baseUrlServer + '/login/loginPwd', {
"loginNo": id
, "loginPwd": mdp
, "domainNo": 0
})
.then(function (res) {
cb(res.data, id)
})
.catch(function (error) {
cb(error)
})
}
}
module.exports = M_Login
EDIT : I found the problem, it was on the req.session of the routes.js
I think that jest don't know express session and thats why the test never finish