Skip to content

Commit

Permalink
chore(apps/staking): Deprecate axios from useMarketInformation custom…
Browse files Browse the repository at this point in the history
… hook
  • Loading branch information
nevendyulgerov committed Feb 21, 2025
1 parent d313b5a commit 6696a69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions __tests__/services/market.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof axios.get>;
global.fetch = jest.fn();
const mockFetchGet = global.fetch as jest.MockedFunction<typeof global.fetch>;

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 () => {
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions src/services/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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({
Expand Down

0 comments on commit 6696a69

Please sign in to comment.