Skip to content

Commit

Permalink
Upgrade eslint and rewrite to modern js
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Oct 9, 2024
1 parent 6acbf99 commit c1b4a0f
Show file tree
Hide file tree
Showing 25 changed files with 556 additions and 540 deletions.
22 changes: 0 additions & 22 deletions .eslintrc

This file was deleted.

26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ axios-mock-adapter works on Node as well as in a browser, it works with axios v0
Mocking a `GET` request

```js
var axios = require("axios");
var AxiosMockAdapter = require("axios-mock-adapter");
const axios = require("axios");
const AxiosMockAdapter = require("axios-mock-adapter");

// This sets the mock adapter on the default instance
var mock = new AxiosMockAdapter(axios);
const mock = new AxiosMockAdapter(axios);

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

```js
var axios = require("axios");
var AxiosMockAdapter = require("axios-mock-adapter");
const axios = require("axios");
const AxiosMockAdapter = require("axios-mock-adapter");

// This sets the mock adapter on the default instance
var mock = new AxiosMockAdapter(axios);
const mock = new AxiosMockAdapter(axios);

// Mock GET request to /users when param `searchText` is 'John'
// arguments for reply are (status, data, headers)
Expand All @@ -65,7 +65,7 @@ To add a delay to responses, specify a delay amount (in milliseconds) when insta

```js
// All requests using this instance will have a 2 seconds delay:
var mock = new AxiosMockAdapter(axiosInstance, { delayResponse: 2000 });
const mock = new AxiosMockAdapter(axiosInstance, { delayResponse: 2000 });
```

You can restore the original adapter (which will remove the mocking behavior)
Expand Down Expand Up @@ -279,15 +279,15 @@ If you set `onNoMatch` option to `passthrough` all requests would be forwarded o
```js
// Mock all requests to /foo with HTTP 200, but forward
// any others requests to server
var mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "passthrough" });
const mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "passthrough" });

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

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.

```js
var mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "throwException" });
const mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "throwException" });

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

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

```js
var normalAxios = axios.create();
var mockAxios = axios.create();
var mock = new AxiosMockAdapter(mockAxios);
const normalAxios = axios.create();
const mockAxios = axios.create();
const mock = new AxiosMockAdapter(mockAxios);

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

feature
Expand Down
65 changes: 65 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use strict";

module.exports = [
{
ignores: [
"dist/"
]
},
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "commonjs"
},

rules: {
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
quotes: [
2,
"double",
{
avoidEscape: true,
allowTemplateLiterals: true
}
],
"comma-dangle": [2, "only-multiline"],
"curly": [2, "multi-line"],
"eol-last": 2,
"eqeqeq": 2,
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": 2,
"new-cap": 0,
"no-native-reassign": 2,
"no-extra-semi": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
// "no-param-reassign": [2, { "props": false }],
"no-trailing-spaces": 2,
"no-underscore-dangle": 0,
"no-unused-vars": [
2,
{
vars: "all",
args: "none",
caughtErrors: "all",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_"
}
],
"object-curly-spacing": [2, "always"],
"padded-blocks": [2, "never"],
"semi": [2, "always"],
"space-before-blocks": [2, "always"],
"no-var": 2,
"prefer-const": [
2,
{
destructuring: "any",
ignoreReadBeforeAssign: true
}
],

"prefer-promise-reject-errors": 2,
"prefer-template": 2
}
}
];
Loading

0 comments on commit c1b4a0f

Please sign in to comment.