chai-http icon indicating copy to clipboard operation
chai-http copied to clipboard

How to get req object?

Open Arrow7000 opened this issue 8 years ago • 5 comments

In the documentation you show how it's possible to access cookies:

image

But where do you actually get the req object from? This isn't explained anywhere in the documentation.

Arrow7000 avatar Feb 07 '17 12:02 Arrow7000

I'm curious as well. please if anyone found out please leave a note.

yipcma avatar Jul 09 '17 23:07 yipcma

I believe the response object (res) should have the request object (req) attached to it:

app.get('/').then(res => res.req).then(req => expect(req.to.have.cookie('session_id');

If someone would like to confirm this and send a PR updating the docs, that'd be great!

keithamus avatar Jul 10 '17 06:07 keithamus

I tried res.req.body and it returns undefined, wonder if the body-parser would work in the test.

yipcma avatar Jul 10 '17 09:07 yipcma

@yipcma what are you expecting res.req.body to be? Do you have a reduced test case I could look at?

keithamus avatar Jul 10 '17 10:07 keithamus

it's a text, and i have body-parser.text() as middle-ware in my express server. I'm expecting text.

yipcma avatar Jul 10 '17 10:07 yipcma