dimanche 24 janvier 2021

Mocha test timeoutting

I'm kinda new to tests(even js too lmao), I'm experiencing some technical difficulties. This is my function:

var register = async ({ body: { username, password } }, res) => {
    if (!(await client.existsAsync(username))) {
        client.set(username,  password , redis.print);
        const nick = await client.keysAsync(username)
        res.status(201).json({
            message: "Success",
            user: nick[0]
        })
    } else {
        res.status(400).json({ message: "Username already used" })
    }
}

It's a simple register function, if everything goes well I store these values in my RedisDB and I get 201(function already tested through Postman).

This is the test function:

describe('POST /auth/register', () => {
    it('test success', async () =>{
        const {status} = await request(auth).post('/register').send({
            username: "pippo",
            password: "paperino"
        }).set('Accept', 'application/json')
        status.should.equal(201)
    })
})

This is what I get:

Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

What should i do? (I've already increased timeout to 10s)

Aucun commentaire:

Enregistrer un commentaire