From 6696a69beadc0fc3cc6f4c0bb8db34c21b249227 Mon Sep 17 00:00:00 2001 From: Neven Dyulgerov Date: Mon, 17 Feb 2025 12:35:03 +0200 Subject: [PATCH] chore(apps/staking): Deprecate axios from useMarketInformation custom hook --- __tests__/services/market.test.ts | 18 ++++++++++-------- src/services/market.ts | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/__tests__/services/market.test.ts b/__tests__/services/market.test.ts index ba8a45a3..8863d835 100644 --- a/__tests__/services/market.test.ts +++ b/__tests__/services/market.test.ts @@ -10,18 +10,20 @@ // PARTICULAR PURPOSE. See the GNU General Public License for more details. import { act, renderHook, waitFor } from '@testing-library/react'; -import axios from 'axios'; -import { useMarketInformation, endpoint } from '../../src/services/market'; +import { endpoint, useMarketInformation } from '../../src/services/market'; jest.mock('axios'); -const mockAxiosGet = axios.get as jest.MockedFunction; +global.fetch = jest.fn(); +const mockFetchGet = global.fetch as jest.MockedFunction; describe('market service', () => { it('should invoke GET http request with correct endpoint', async () => { let url = null; - mockAxiosGet.mockImplementation((endpoint) => { + mockFetchGet.mockImplementation((endpoint) => { url = endpoint; - return Promise.resolve({ data: {} }); + return Promise.resolve({ + json: () => new Promise((resolve) => resolve({})), + } as Response); }); await act(async () => { @@ -45,10 +47,10 @@ describe('market service', () => { circulating_supply: 10, }, }; - mockAxiosGet.mockImplementation(() => { + mockFetchGet.mockImplementation(() => { return Promise.resolve({ - data, - }); + json: () => new Promise((resolve) => resolve(data)), + } as Response); }); const { result } = renderHook(() => useMarketInformation()); diff --git a/src/services/market.ts b/src/services/market.ts index a05ba014..4626da67 100644 --- a/src/services/market.ts +++ b/src/services/market.ts @@ -10,7 +10,6 @@ // PARTICULAR PURPOSE. See the GNU General Public License for more details. import { useEffect, useState } from 'react'; -import axios from 'axios'; export type MarketInformation = { price?: number; @@ -29,9 +28,10 @@ export const useMarketInformation = () => { useEffect(() => { setLoading(true); setError(''); - axios - .get(endpoint) - .then(({ data }) => { + + fetch(endpoint) + .then((res) => res.json()) + .then((data) => { setLoading(false); setError(''); setMarketInformation({