mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
fix jest tests
This commit is contained in:
@@ -41,3 +41,15 @@ global.console = {
|
||||
consoleError(...args);
|
||||
},
|
||||
};
|
||||
|
||||
// Polyfill for structuredClone
|
||||
if (typeof structuredClone === 'undefined') {
|
||||
global.structuredClone = <T>(obj: T): T => {
|
||||
try {
|
||||
return JSON.parse(JSON.stringify(obj)) as T;
|
||||
} catch (error) {
|
||||
// Fallback for circular references and other special cases
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
|
||||
import theme from 'toolkit/theme/theme';
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { act } from 'react';
|
||||
|
||||
import { renderHook, wrapper } from 'jest/lib';
|
||||
|
||||
import useRatings from './useRatings';
|
||||
@@ -5,7 +7,11 @@ import useRatings from './useRatings';
|
||||
const useAccount = jest.fn();
|
||||
const useApiQuery = jest.fn();
|
||||
|
||||
jest.mock('lib/hooks/useToast', () => jest.fn());
|
||||
jest.mock('toolkit/chakra/toaster', () => ({
|
||||
toaster: {
|
||||
error: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('wagmi', () => ({ useAccount: () => useAccount() }));
|
||||
jest.mock('lib/api/useApiQuery', () => () => useApiQuery());
|
||||
|
||||
@@ -19,7 +25,12 @@ it('should set canRate to true if address is defined and transactions_count is 5
|
||||
isPlaceholderData: false,
|
||||
data: { transactions_count: 5 },
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useRatings(), { wrapper });
|
||||
await act(async() => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(result.current.canRate).toBe(true);
|
||||
});
|
||||
|
||||
@@ -29,7 +40,12 @@ it('should set canRate to undefined if address is undefined', async() => {
|
||||
isPlaceholderData: false,
|
||||
data: { transactions_count: 5 },
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useRatings(), { wrapper });
|
||||
await act(async() => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(result.current.canRate).toBe(undefined);
|
||||
});
|
||||
|
||||
@@ -39,7 +55,12 @@ it('should set canRate to false if transactions_count is less than 5', async() =
|
||||
isPlaceholderData: false,
|
||||
data: { transactions_count: 4 },
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useRatings(), { wrapper });
|
||||
await act(async() => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(result.current.canRate).toBe(false);
|
||||
});
|
||||
|
||||
@@ -49,7 +70,12 @@ it('should set canRate to false if isPlaceholderData is true', async() => {
|
||||
isPlaceholderData: true,
|
||||
data: { transactions_count: 5 },
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useRatings(), { wrapper });
|
||||
await act(async() => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(result.current.canRate).toBe(false);
|
||||
});
|
||||
|
||||
@@ -59,7 +85,12 @@ it('should set canRate to false if data is undefined', async() => {
|
||||
isPlaceholderData: false,
|
||||
data: undefined,
|
||||
});
|
||||
const { result } = renderHook(() => useRatings());
|
||||
|
||||
const { result } = renderHook(() => useRatings(), { wrapper });
|
||||
await act(async() => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(result.current.canRate).toBe(false);
|
||||
});
|
||||
|
||||
@@ -69,6 +100,11 @@ it('should set canRate to false if transactions_count is undefined', async() =>
|
||||
isPlaceholderData: false,
|
||||
data: {},
|
||||
});
|
||||
const { result } = renderHook(() => useRatings());
|
||||
|
||||
const { result } = renderHook(() => useRatings(), { wrapper });
|
||||
await act(async() => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
expect(result.current.canRate).toBe(false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user