Supertest: From 3.x to 4.x, is there a new way to use request() ?

Created on 11 Mar 2019  路  11Comments  路  Source: visionmedia/supertest

if I call my API in this way using Supertest 4.x:

return res.status(401).send()

and try to assert it in this way:

response = await request(app).post('/admin').send( { data_here } )
expect(response.status).toBe(401);

Supertest returns Unauthorized and not status code 401 as I'm expecting.

If I do the same thing using Supertest 3.x , it returns the status code I'm expecting to test it.

Is there a new way to do it on version 4.x ?

needs-investigation

Most helpful comment

Same here, used this in 3.x:

  await request(app)
    .post('/system/invoice/generate')
    .set('content-type', 'application/json')
    .set('Authorization', 'invalidtoken')
    .send()
    .expect(httpStatus.UNAUTHORIZED)

Short migration guide would be nice

All 11 comments

We used to set the expected status code, like 401, but that no longer returns the response, it throws the error instead.
Seems like a breaking change without documentation.

Same here, used this in 3.x:

  await request(app)
    .post('/system/invoice/generate')
    .set('content-type', 'application/json')
    .set('Authorization', 'invalidtoken')
    .send()
    .expect(httpStatus.UNAUTHORIZED)

Short migration guide would be nice

same and has been reported yesterday but still no fixes.

Don't you have any tests which cover these cases? I mean there was already something similar:

https://github.com/visionmedia/supertest/issues/534

Don't you have any tests which cover these cases? I mean there was already something similar:

534

Feel free to open an PR and add those tests 馃憤

I鈥檝e started adding a few tests, the problem is all the tests use callbacks only, so the regression was overlooked, again (sorry!).

Just to be clear, my comment was in @akirilyuk s direction.

@SMenigat should not the person who created the fix also add the tests which verifies the error wont happen again? Also should it not be the maintainers job to have meaningful tests for their own product?

+1 with @akirilyuk

558 merged, I close this issue.

Thank you 馃檹

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonathanong picture jonathanong  路  4Comments

DeaconDesperado picture DeaconDesperado  路  6Comments

ghost picture ghost  路  5Comments

nareshbhatia picture nareshbhatia  路  6Comments

ryami333 picture ryami333  路  4Comments