samedi 30 mars 2019

How to fix "not ok timeout!" when testing fastify route?

I am trying to test fastify route with tap. Here is the test file:

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

tap.test('GET `/` route', t => {
    t.plan(4)

    const fastify = buildFastify()

    // At the end of your tests it is highly recommended to call `.close()`
    // to ensure that all connections to external services get closed.
    t.tearDown(() => {
        fastify.close();
    });

    fastify.inject({
        method: 'GET',
        url: '/'
    }, async (err, response) => {
        t.error(err)
        t.strictEqual(response.statusCode, 200)
        t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
        t.deepEqual(JSON.parse(response.payload), { hello: 'world' })
        t.done()
    })
})

After running test I see in the console:

....Closing mongoose connection ...
listening on 3001
tests/routes/status.test.js ........................... 4/5 30s
  not ok timeout!

running tests with npm script: "test": "env-cmd ./test.env tap tests/routes/status.test.js"

Aucun commentaire:

Enregistrer un commentaire