Skip to content

Commit c1b4a0f

Browse files
committed
Upgrade eslint and rewrite to modern js
1 parent 6acbf99 commit c1b4a0f

25 files changed

+556
-540
lines changed

.eslintrc

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ axios-mock-adapter works on Node as well as in a browser, it works with axios v0
2020
Mocking a `GET` request
2121

2222
```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");
2525

2626
// This sets the mock adapter on the default instance
27-
var mock = new AxiosMockAdapter(axios);
27+
const mock = new AxiosMockAdapter(axios);
2828

2929
// Mock any GET request to /users
3030
// arguments for reply are (status, data, headers)
@@ -40,11 +40,11 @@ axios.get("/users").then(function (response) {
4040
Mocking a `GET` request with specific parameters
4141

4242
```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");
4545

4646
// This sets the mock adapter on the default instance
47-
var mock = new AxiosMockAdapter(axios);
47+
const mock = new AxiosMockAdapter(axios);
4848

4949
// Mock GET request to /users when param `searchText` is 'John'
5050
// 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
6565

6666
```js
6767
// 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 });
6969
```
7070

7171
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
279279
```js
280280
// Mock all requests to /foo with HTTP 200, but forward
281281
// any others requests to server
282-
var mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "passthrough" });
282+
const mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "passthrough" });
283283

284284
mock.onAny("/foo").reply(200);
285285
```
286286

287287
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.
288288

289289
```js
290-
var mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "throwException" });
290+
const mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "throwException" });
291291

292292
mock.onAny("/foo").reply(200);
293293

@@ -323,9 +323,9 @@ mock.onGet("/product").reply(function (config) {
323323
Composing from multiple sources with Promises:
324324

325325
```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);
329329

330330
mock
331331
.onGet("/orders")
@@ -351,7 +351,7 @@ This is useful for testing.
351351
```js
352352
describe("Feature", () => {
353353
it("requests an endpoint", (done) => {
354-
var mock = new AxiosMockAdapter(axios);
354+
const mock = new AxiosMockAdapter(axios);
355355
mock.onPost("/endpoint").replyOnce(200);
356356

357357
feature

eslint.config.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use strict";
2+
3+
module.exports = [
4+
{
5+
ignores: [
6+
"dist/"
7+
]
8+
},
9+
{
10+
languageOptions: {
11+
ecmaVersion: 2022,
12+
sourceType: "commonjs"
13+
},
14+
15+
rules: {
16+
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
17+
quotes: [
18+
2,
19+
"double",
20+
{
21+
avoidEscape: true,
22+
allowTemplateLiterals: true
23+
}
24+
],
25+
"comma-dangle": [2, "only-multiline"],
26+
"curly": [2, "multi-line"],
27+
"eol-last": 2,
28+
"eqeqeq": 2,
29+
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
30+
"keyword-spacing": 2,
31+
"new-cap": 0,
32+
"no-native-reassign": 2,
33+
"no-extra-semi": 2,
34+
"no-multiple-empty-lines": [2, { "max": 1 }],
35+
// "no-param-reassign": [2, { "props": false }],
36+
"no-trailing-spaces": 2,
37+
"no-underscore-dangle": 0,
38+
"no-unused-vars": [
39+
2,
40+
{
41+
vars: "all",
42+
args: "none",
43+
caughtErrors: "all",
44+
argsIgnorePattern: "^_",
45+
caughtErrorsIgnorePattern: "^_"
46+
}
47+
],
48+
"object-curly-spacing": [2, "always"],
49+
"padded-blocks": [2, "never"],
50+
"semi": [2, "always"],
51+
"space-before-blocks": [2, "always"],
52+
"no-var": 2,
53+
"prefer-const": [
54+
2,
55+
{
56+
destructuring: "any",
57+
ignoreReadBeforeAssign: true
58+
}
59+
],
60+
61+
"prefer-promise-reject-errors": 2,
62+
"prefer-template": 2
63+
}
64+
}
65+
];

0 commit comments

Comments
 (0)