fmidev / weather-app

FMI's official weather application for mobile devices
7 stars 2 forks source link

Fix ConfigProvider tests #591

Open geosaaga opened 3 months ago

geosaaga commented 3 months ago

After adding axios-cache-interceptor to AxiosClient ConfigProvider tests have been broken:

 FAIL  __tests__/config/provider.test.tsx
  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'defaults')

      3 |
      4 | const instance = Axios.create();
    > 5 | const axios = setupCache(instance);
        |                         ^
      6 |
      7 | const axiosClient = async (
      8 |   options: AxiosRequestConfig,

      at defaults (node_modules/axios-cache-interceptor/src/cache/create.ts:32:18)
      at Object.<anonymous> (src/utils/axiosClient.ts:5:25)
      at Object.require (src/config/DynamicConfig.ts:1:1)
      at Object.require (src/config/ConfigProvider.tsx:4:1)
      at Object.require (src/config/index.ts:1:1)
      at Object.require (__tests__/config/provider.test.tsx:6:1)

Couldn't find easy way to fix tests even tried to add setupCache mock like suggested here

https://stackoverflow.com/questions/76875859/how-to-globally-mock-axios-cache-interceptor