I'm new to supertest, so I'm not sure I'm doing something wrong...
I'm using Ava and I have the following test case:
test('Get thirdPartyMedia By Id', async t => {
const id = String(dbFixtures.valid.thirdPartyMedia._id)
await request(app)
.get(`/third-party-media/${id}`)
.expect(200)
})
Notice: app is set on before hook.
The request is triggered properly and the response is what I expected, however, I get the following error:
Test finished without running any assertions
If I change the expected status code to any other value, the test fails as expected.
To me it looks like a Ava issue not supertest. .expect is part of supertest not Ava, at least I wondered this same thing just recently.
const response = await request(app)...
// see Ava assertions from Ava github page e.g.
t.truthy(response.body.thirdpartymedia.or.whatever)
why the test must have the assertion?
Ava considers no assertion present in a test an error. But the assertion is being performed
I use other libraries with Ava that are framework agnostic and they work just fine.
Only with supertest I'm having this issue.
AFAIK you can use something like this
test('Get thirdPartyMedia By Id', async t => {
const id = String(dbFixtures.valid.thirdPartyMedia._id)
const res = await request(app)
.get(`/third-party-media/${id}`)
t.is(res.status, 200)
})
or you can disable an option in ava to treat tests without assertions like failures.
"failWithoutAssertions": false
@havenchyk I'm not sure this is a good idea.
Currently, I just add:
t.pass()
as last line of the unit test function.
well, t.pass() isn't better IMHO. Here is a recommended way that is described in ava docs.
Anyway, I don't see how this issue can be addressed in this repository
I've openned this issue because I didn't understand by that time why supertest .expect() syntax didn't work with ava, as it is shorter.
The file you pointed out was created on Aug 5, 2017, about 1 month before I created this issue. I can't remember why I wasn't able to find it at that time :sweat_smile:.
Anyway you're right, if the official ava docs state that there is a recommended way, I should stick to it.
Thank's a lot @havenchyk
Also, now I remember I did find out that testdouble had the same issue when working with ava, so this is definitely not a supertest specific issue.