ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.44k stars 241 forks source link

include supported axios minor version near the top of documentation #331

Closed xenoterracide closed 1 year ago

xenoterracide commented 2 years ago

context below, my version of the mock did not line up with the axios version we're using, could you include the supported version near the top of your documentation please


getting this error

TS2345: Argument of type 'AxiosStatic' is not assignable to parameter of type 'AxiosInstance'.   Types of property 'defaults' are incompatible.     Type 'AxiosRequestConfig' is not assignable to type 'AxiosDefaults<any>'.       Property 'headers' is optional in type 'AxiosRequestConfig' but required in type 'AxiosDefaults<any>'.

here's my code

import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'

describe('sociable Controller test', () => {
  const mock = new MockAdapter(axios)
  it('suck', () => {
    mock.adapter()
  })
})
❯ node --version && npm --version && npm ls typescript axios
v16.14.0
8.5.1
@cof/e1-root@ ...
└─┬ back-end@0.0.0 -> ./back-end
  ├─┬ @chassisjs/devexchange-caller@2.4.0
  │ └── axios@0.21.4 deduped
  ├─┬ @cof/e1-workflow-module@0.0.0 -> ./packages/workflow-module
  │ ├─┬ @cof/e1-models@0.0.0 -> ./packages/models
  │ │ ├─┬ ts-node@8.10.2
  │ │ │ └── typescript@4.3.5 deduped
  │ │ └── typescript@4.3.5 deduped
  │ ├─┬ ts-node@8.10.2
  │ │ └── typescript@4.3.5 deduped
  │ └── typescript@4.3.5 deduped
  ├─┬ @typescript-eslint/eslint-plugin@5.13.0
  │ └─┬ tsutils@3.21.0
  │   └── typescript@4.3.5 deduped
  ├─┬ axios-mock-adapter@1.20.0
  │ └── axios@0.24.0
  ├── axios@0.21.4
  ├─┬ ts-node@8.10.2
  │ └── typescript@4.3.5 deduped
  └── typescript@4.3.5
fritzfelix commented 1 year ago

Also getting the same error.

The readme here claims compatibility since axios v0.17, but already then axios exported the type AxiosStatic (https://github.com/axios/axios/blob/v0.17.0/index.d.ts#L124) but this library here requires AxiosInstance (https://github.com/ctimmerm/axios-mock-adapter/blob/master/types/index.d.ts#L56).

@ctimmerm Mind fixing the type?