Hi,
Today I decided to make some simple REST API and make functional test with Adonis.
My test looks like this:
'use strict'
const { test, trait } = use('Test/Suite')('Template')
const Template = use('App/Models/Template')
trait('Test/ApiClient')
test('get list of templates', async ({ client, done }) => {
const response = await client
.get('/template')
.end()
response.assertStatus(200)
})
but after adonis test i get error:
1. get list of templates
Error: Test timeout, ensure "done()" is called; if returning a Promise, ensure it resolves.
at Test._parseError (G:\Projekty\Akcelerator\adonis\szablony_dokumentow\node_modules\japa\src\Test.js:109:16)
at Callable.args.run.then.then.catch (G:\Projekty\Akcelerator\adonis\szablony_dokumentow\node_modules\japa\src\Test.js:195:21)
Can anyone explain what I'm doing wrong?
Basically what it says, you're supposed to call done when the function completes and you're not calling it.
test('get list of templates', async ({ client, done }) => {
const response = await client
.get('/template')
.end()
response.assertStatus(200)
return done()
})
Basically what is says is something else
Error: Test timeout, ensure "done()" is called; if returning a Promise, ensure it resolves.
The test has been timed-out, which means you need to increase the test time. The safest way is to set it to 0, which means disable timeouts.
test('get list of templates', async ({ client, done }) => {
const response = await client
.get('/template')
.end()
response.assertStatus(200)
}).timeout(0)
The default timeout is 2000ms.
@thetutlage that's a confusing error then. Shouldn't done() get called?
return done() doesn't work.
.timeout(0) works fine.
You should update docs then. Your example api test doesn't say anything about .timeout(0) (or im blind): http://adonisjs.com/docs/4.0/api-tests.
Hey @pawel-miczka! 馃憢
May you sent a PR to https://github.com/adonisjs/docs/ to improve the documentation about testing? 馃槃
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Basically what is says is something else
The test has been timed-out, which means you need to increase the test time. The safest way is to set it to
0, which means disable timeouts.The default timeout is
2000ms.