You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging.
8
8
Does not use a socket connection so can be run against an inactive server (server not in listen mode).
@@ -146,6 +146,7 @@ Injects a fake request into an HTTP server.
146
146
-`authority` - a string specifying the HTTP HOST header value to be used if no header is provided, and the `url`
147
147
does not include an authority component. Defaults to `'localhost'`.
148
148
-`headers` - an optional object containing request headers.
149
+
-`cookies` - an optional object containing key-value pairs that will be encoded and added to `cookie` header. If the header is already set, the data will be appended.
149
150
-`remoteAddress` - an optional string specifying the client remote address. Defaults to `'127.0.0.1'`.
150
151
-`payload` - an optional request payload. Can be a string, Buffer, Stream or object. If the payload is string, Buffer or Stream is used as is as the request payload. Oherwise it is serialized with `JSON.stringify` forcing the request to have the `Content-type` equal to `application/json`
151
152
-`query` - an optional object containing query parameters.
@@ -173,6 +174,7 @@ Injects a fake request into an HTTP server.
173
174
-`rawPayload` - the raw payload as a Buffer.
174
175
-`trailers` - an object containing the response trailers.
175
176
-`json` - a function that parses the `application/json` response payload and returns an object. Throws if the content type does not contain `application/json`.
177
+
-`cookies` - a getter that parses the `set-cookie` response header and returns an array with all the cookies and their metadata.
176
178
177
179
Note: You can also pass a string in place of the `options` object as a shorthand for `{url: string, method: 'GET'}`.
178
180
@@ -184,7 +186,7 @@ Checks if given object `obj` is a *light-my-request* `Request` object.
184
186
185
187
There are following methods you can used as chaining:
186
188
-`delete`, `get`, `head`, `options`, `patch`, `post`, `put`, `trace`. They will set the HTTP request method and also the request URL.
187
-
-`body`, `headers`, `payload`, `query`. They can be used to set the request options object.
189
+
-`body`, `headers`, `payload`, `query`, `cookies`. They can be used to set the request options object.
188
190
189
191
And finally you need to call `end`. It has the signature `function (callback)`.
190
192
If you invoke `end` without a callback function, the method will return a promise, thus you can:
0 commit comments