@@ -20,11 +20,11 @@ axios-mock-adapter works on Node as well as in a browser, it works with axios v0
20
20
Mocking a ` GET ` request
21
21
22
22
``` js
23
- var axios = require (" axios" );
24
- var AxiosMockAdapter = require (" axios-mock-adapter" );
23
+ const axios = require (" axios" );
24
+ const AxiosMockAdapter = require (" axios-mock-adapter" );
25
25
26
26
// This sets the mock adapter on the default instance
27
- var mock = new AxiosMockAdapter (axios);
27
+ const mock = new AxiosMockAdapter (axios);
28
28
29
29
// Mock any GET request to /users
30
30
// arguments for reply are (status, data, headers)
@@ -40,11 +40,11 @@ axios.get("/users").then(function (response) {
40
40
Mocking a ` GET ` request with specific parameters
41
41
42
42
``` js
43
- var axios = require (" axios" );
44
- var AxiosMockAdapter = require (" axios-mock-adapter" );
43
+ const axios = require (" axios" );
44
+ const AxiosMockAdapter = require (" axios-mock-adapter" );
45
45
46
46
// This sets the mock adapter on the default instance
47
- var mock = new AxiosMockAdapter (axios);
47
+ const mock = new AxiosMockAdapter (axios);
48
48
49
49
// Mock GET request to /users when param `searchText` is 'John'
50
50
// arguments for reply are (status, data, headers)
@@ -65,7 +65,7 @@ To add a delay to responses, specify a delay amount (in milliseconds) when insta
65
65
66
66
``` js
67
67
// All requests using this instance will have a 2 seconds delay:
68
- var mock = new AxiosMockAdapter (axiosInstance, { delayResponse: 2000 });
68
+ const mock = new AxiosMockAdapter (axiosInstance, { delayResponse: 2000 });
69
69
```
70
70
71
71
You can restore the original adapter (which will remove the mocking behavior)
@@ -279,15 +279,15 @@ If you set `onNoMatch` option to `passthrough` all requests would be forwarded o
279
279
``` js
280
280
// Mock all requests to /foo with HTTP 200, but forward
281
281
// any others requests to server
282
- var mock = new AxiosMockAdapter (axiosInstance, { onNoMatch: " passthrough" });
282
+ const mock = new AxiosMockAdapter (axiosInstance, { onNoMatch: " passthrough" });
283
283
284
284
mock .onAny (" /foo" ).reply (200 );
285
285
```
286
286
287
287
Using ` onNoMatch ` option with ` throwException ` to throw an exception when a request is made without match any handler. It's helpful to debug your test mocks.
288
288
289
289
``` js
290
- var mock = new AxiosMockAdapter (axiosInstance, { onNoMatch: " throwException" });
290
+ const mock = new AxiosMockAdapter (axiosInstance, { onNoMatch: " throwException" });
291
291
292
292
mock .onAny (" /foo" ).reply (200 );
293
293
@@ -323,9 +323,9 @@ mock.onGet("/product").reply(function (config) {
323
323
Composing from multiple sources with Promises:
324
324
325
325
``` js
326
- var normalAxios = axios .create ();
327
- var mockAxios = axios .create ();
328
- var mock = new AxiosMockAdapter (mockAxios);
326
+ const normalAxios = axios .create ();
327
+ const mockAxios = axios .create ();
328
+ const mock = new AxiosMockAdapter (mockAxios);
329
329
330
330
mock
331
331
.onGet (" /orders" )
@@ -351,7 +351,7 @@ This is useful for testing.
351
351
``` js
352
352
describe (" Feature" , () => {
353
353
it (" requests an endpoint" , (done ) => {
354
- var mock = new AxiosMockAdapter (axios);
354
+ const mock = new AxiosMockAdapter (axios);
355
355
mock .onPost (" /endpoint" ).replyOnce (200 );
356
356
357
357
feature
0 commit comments