failing async test ends in timeout instead of go to catch clause #3311
-
I have some async tests and everything goes ok except when i get some assertion failing. This is very similar to the issue described here. For example, the bellow snippet dies in timeout because the content-type is different to the expected: import test from 'ava'
import request from 'supertest'
import { app, database } from './main.js'
// other tests
test('should get htmx browser script', async t => {
try {
const result = await request(app.callback()).get('/htmx.js')
t.regex(result.header["content-type"], /javascript/)
t.is(200, result.status)
} catch (e) {
t.fail(e.message)
}
}) But first i got the timeout and only then i get the message regarding the failing regex match: Any guidance on how to avoid timeout is welcome. The sample code, ava version and everything else is in this repo. |
Beta Was this translation helpful? Give feedback.
Answered by
novemberborn
Feb 27, 2024
Replies: 1 comment 1 reply
-
The database isn't destroyed when the test fails. This code doesn't run after failures: test.after(async t => {
await database.destroy()
}) Use the test.after.always(async t => {
await database.destroy()
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sombriks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The database isn't destroyed when the test fails. This code doesn't run after failures:
Use the
.always
modifier instead: