jeudi 7 janvier 2021

Can you add to the request object when using supertest?

In my project, user information is stored on req.user.

Is there a way in supertest that the same functionality can be achieved, so that a user object can be appended to the request and read in the middleware/controllers for testing (mocha)? My issue at the moment is that the tests will not pass the middleware checks without this information.

I know that you can set header and body attributes, however, my issue here is that this would require a change to my code to reference req.headers.user or req.body.user, rather than simply be on the request object itself - so is not ideal for my use case.

Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire