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
To make the request and assert on its response, the `end` method can be used:
172
194
173
195
```js
174
-
chai.request.execute(app)
196
+
import {request} from'chai-http';
197
+
198
+
request.execute(app)
175
199
.put('/user/me')
176
200
.send({ password:'123', confirmPassword:'123' })
177
201
.end((err, res) => {
@@ -193,8 +217,10 @@ accomplished using the
193
217
callback has completed, and the assertions can be verified:
194
218
195
219
```js
220
+
import {request} from'chai-http';
221
+
196
222
it('fails, as expected', function(done) { // <= Pass in done callback
197
-
chai.request.execute('http://localhost:8080')
223
+
request.execute('http://localhost:8080')
198
224
.get('/')
199
225
.end((err, res) => {
200
226
expect(res).to.have.status(123);
@@ -203,7 +229,7 @@ it('fails, as expected', function(done) { // <= Pass in done callback
203
229
});
204
230
205
231
it('succeeds silently!', () => { // <= No done callback
206
-
chai.request.execute('http://localhost:8080')
232
+
request.execute('http://localhost:8080')
207
233
.get('/')
208
234
.end((err, res) => {
209
235
expect(res).to.have.status(123); // <= Test completes before this runs
@@ -221,7 +247,9 @@ If `Promise` is available, `request()` becomes a Promise capable library -
221
247
and chaining of `then`s becomes possible:
222
248
223
249
```js
224
-
chai.request.execute(app)
250
+
import {request} from'chai-http';
251
+
252
+
request.execute(app)
225
253
.put('/user/me')
226
254
.send({ password:'123', confirmPassword:'123' })
227
255
.then((res) => {
@@ -238,8 +266,10 @@ Sometimes you need to keep cookies from one request, and send them with the
238
266
next (for example, when you want to login with the first request, then access an authenticated-only resource later). For this, `.request.agent()` is available:
239
267
240
268
```js
269
+
import {request} from'chai-http';
270
+
241
271
// Log in
242
-
constagent=chai.request.agent(app)
272
+
constagent=request.agent(app)
243
273
agent
244
274
.post('/session')
245
275
.send({ username:'me', password:'123' })
@@ -254,7 +284,7 @@ agent
254
284
});
255
285
```
256
286
257
-
Note: The server started by `chai.request.agent(app)` will not automatically close following the test(s). You should call `agent.close()` after your tests to ensure your program exits.
287
+
Note: The server started by `request.agent(app)` will not automatically close following the test(s). You should call `agent.close()` after your tests to ensure your program exits.
0 commit comments