dimanche 7 février 2021

Asynchronous test with mocha and chai GET doesn't work for NodeJS Rest API

thanks in advance for your reading!

I'm struggling with testing even after looking for example and tutorials, my test are not working but I'm not sure if the issue is chai related or my API server.

All the code is open source and available here.

I have an endpoint who should return all exercises as a list: GET /v1/exercises

Here is my test:

'use strict'

const chai = require('chai')
const chaiHttp = require('chai-http')
chai.should()

const app = require('../src/app')

chai.use(chaiHttp)
const expect = require('chai').expect

describe('Exercise', () => {
  it('Should get all exercises', (done) => {
    chai
      .request(app)
      .get('/v1/exercises')
      .end((err, res) => {
        const result = res.statusCode
        expect(result).to.equal(200)
        done()
      })
  })
})

And I get this error:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/kevintassi/Documents/project/fitigai/api/test/01.exercise.spec.js)

You can see files here:

Do you know why this issue come? Note that I don't have this error is the endpoint is wrong, so the timeout is appear only when the function is processing I guess. But still don't get why.

I thanks you a lot in advance for your time. Feel free to ask me more details is needed.

Aucun commentaire:

Enregistrer un commentaire