Skip to content

Commit

Permalink
chore: explicit vitest imports (#1252)
Browse files Browse the repository at this point in the history
  • Loading branch information
avidreder authored Sep 13, 2024
1 parent 8a1a1b2 commit 0435fa0
Show file tree
Hide file tree
Showing 66 changed files with 275 additions and 240 deletions.
12 changes: 6 additions & 6 deletions src/api/buildSwapTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { CDP_GET_SWAP_TRADE } from '../network/definitions/swap';
import { sendRequest } from '../network/request';
import { DEGEN_TOKEN, ETH_TOKEN } from '../swap/mocks';
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('buildSwapTransaction', () => {
chainId: '8453',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const trade = mockResponse.result;
const expectedResponse = {
approveTransaction: undefined,
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('buildSwapTransaction', () => {
chainId: '8453',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const trade = mockResponse.result;
const expectedResponse = {
approveTransaction: undefined,
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('buildSwapTransaction', () => {
chainId: '8453',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const trade = mockResponse.result;
const expectedResponse = {
approveTransaction: getSwapTransaction(trade.approveTx, trade.chainId),
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('buildSwapTransaction', () => {
const mockError = new Error(
'buildSwapTransaction: Error: Failed to send request',
);
(sendRequest as vi.Mock).mockRejectedValue(mockError);
(sendRequest as Mock).mockRejectedValue(mockError);
const error = await buildSwapTransaction(mockParams);
expect(error).toEqual({
code: 'UNCAUGHT_SWAP_ERROR',
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('buildSwapTransaction', () => {
message: 'Invalid response',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const error = await buildSwapTransaction(mockParams);
expect(error).toEqual({
code: 'SWAP_ERROR',
Expand Down
14 changes: 7 additions & 7 deletions src/api/getSwapQuote.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { type Mock, afterEach, describe, expect, it, vi } from 'vitest';
import { CDP_GET_SWAP_QUOTE } from '../network/definitions/swap';
import { sendRequest } from '../network/request';
import { DEGEN_TOKEN, ETH_TOKEN } from '../swap/mocks';
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('getSwapQuote', () => {
slippage: '3',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const quote = await getSwapQuote(mockParams);
expect(quote).toEqual(mockResponse.result);
expect(sendRequest).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('getSwapQuote', () => {
slippage: '3',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const quote = await getSwapQuote(mockParams);
expect(quote).toEqual(mockResponse.result);
expect(sendRequest).toHaveBeenCalledTimes(1);
Expand All @@ -101,7 +101,7 @@ describe('getSwapQuote', () => {
};
const mockApiParams = getAPIParamsForToken(mockParams);
const mockError = new Error('getSwapQuote: Error: Failed to send request');
(sendRequest as vi.Mock).mockRejectedValue(mockError);
(sendRequest as Mock).mockRejectedValue(mockError);
const error = await getSwapQuote(mockParams);
expect(error).toEqual({
code: 'UNCAUGHT_SWAP_QUOTE_ERROR',
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('getSwapQuote', () => {
message: 'Invalid response',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const error = await getSwapQuote(mockParams);
expect(error).toEqual({
code: 'SWAP_QUOTE_ERROR',
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('getSwapQuote', () => {
slippage: '30',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
await getSwapQuote(mockParams);
expect(sendRequest).toHaveBeenCalledTimes(1);
expect(sendRequest).toHaveBeenCalledWith(CDP_GET_SWAP_QUOTE, [
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('getSwapQuote', () => {
slippage: '3',
},
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
await getSwapQuote(mockParams);
expect(sendRequest).toHaveBeenCalledTimes(1);
expect(sendRequest).toHaveBeenCalledWith(CDP_GET_SWAP_QUOTE, [
Expand Down
10 changes: 5 additions & 5 deletions src/api/getTokens.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { type Mock, afterEach, describe, expect, it, vi } from 'vitest';
import { CDP_LIST_SWAP_ASSETS } from '../network/definitions/swap';
import { sendRequest } from '../network/request';
/**
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('getTokens', () => {
],
error: null,
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const tokens = await getTokens();
expect(tokens).toEqual([
{
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('getTokens', () => {
],
error: null,
};
(sendRequest as vi.Mock).mockResolvedValue(mockResponse);
(sendRequest as Mock).mockResolvedValue(mockResponse);
const tokens = await getTokens({ limit: '1', page: '1' });
expect(tokens).toEqual([
{
Expand All @@ -94,7 +94,7 @@ describe('getTokens', () => {
});

it('should return an error object if sendRequest returns an error', async () => {
(sendRequest as vi.Mock).mockResolvedValue({
(sendRequest as Mock).mockResolvedValue({
result: null,
error: {
code: -1,
Expand All @@ -118,7 +118,7 @@ describe('getTokens', () => {
const mockError = new Error(
'getTokens: error retrieving tokens: Token retrieval failed',
);
(sendRequest as vi.Mock).mockRejectedValue(mockError);
(sendRequest as Mock).mockRejectedValue(mockError);
const error = await getTokens();
expect(error).toEqual({
code: 'AmGTa02',
Expand Down
15 changes: 8 additions & 7 deletions src/farcaster/getFarcasterUserAddress.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { getCustodyAddressForFidNeynar } from '../network/neynar/getCustodyAddressForFidNeynar';
import { getVerifiedAddressesForFidNeynar } from '../network/neynar/getVerifiedAddressesForFidNeynar';
import { getFarcasterUserAddress } from './getFarcasterUserAddress';
Expand All @@ -13,17 +14,17 @@ describe('getFarcasterUserAddress function', () => {

it('should return null if any API call fails', async () => {
const error = new Error('Something went wrong');
(getVerifiedAddressesForFidNeynar as vi.Mock).mockRejectedValue(error);
(getVerifiedAddressesForFidNeynar as Mock).mockRejectedValue(error);
const result = await getFarcasterUserAddress(123);
expect(result).toBeNull();
});

it('should return both custody and verified addresses by default', async () => {
const expectedCustodyAddress = 'mock-custody-address';
(getCustodyAddressForFidNeynar as vi.Mock).mockResolvedValue(
(getCustodyAddressForFidNeynar as Mock).mockResolvedValue(
expectedCustodyAddress,
);
(getVerifiedAddressesForFidNeynar as vi.Mock).mockResolvedValue([
(getVerifiedAddressesForFidNeynar as Mock).mockResolvedValue([
expectedCustodyAddress,
]);

Expand All @@ -48,10 +49,10 @@ describe('getFarcasterUserAddress function', () => {
'mock-verified-address-1',
'mock-verified-address-2',
];
(getCustodyAddressForFidNeynar as vi.Mock).mockResolvedValue(
(getCustodyAddressForFidNeynar as Mock).mockResolvedValue(
expectedCustodyAddress,
);
(getVerifiedAddressesForFidNeynar as vi.Mock).mockResolvedValue(
(getVerifiedAddressesForFidNeynar as Mock).mockResolvedValue(
expectedVerifiedAddresses,
);
const result = await getFarcasterUserAddress(123, {
Expand All @@ -66,7 +67,7 @@ describe('getFarcasterUserAddress function', () => {

it('should only return custodyAddress when hasVerifiedAddresses is false', async () => {
const expectedCustodyAddress = 'mock-custody-address';
(getCustodyAddressForFidNeynar as vi.Mock).mockResolvedValue(
(getCustodyAddressForFidNeynar as Mock).mockResolvedValue(
expectedCustodyAddress,
);
const result = await getFarcasterUserAddress(123, {
Expand All @@ -80,7 +81,7 @@ describe('getFarcasterUserAddress function', () => {
'mock-verified-address-1',
'mock-verified-address-2',
];
(getVerifiedAddressesForFidNeynar as vi.Mock).mockResolvedValue(
(getVerifiedAddressesForFidNeynar as Mock).mockResolvedValue(
expectedVerifiedAddresses,
);
const result = await getFarcasterUserAddress(123, {
Expand Down
10 changes: 5 additions & 5 deletions src/identity/components/Address.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { render, screen } from '@testing-library/react';
import { vi } from 'vitest';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import '@testing-library/jest-dom';
import { getSlicedAddress } from '../utils/getSlicedAddress';
import { Address } from './Address';
import { useIdentityContext } from './IdentityProvider';

function mock<T>(func: T) {
return func as vi.Mock;
return func as Mock;
}

const silenceError = () => {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('Address component', () => {
useIdentityContextMock.mockReturnValue({
address: testAddressComponentAddress,
});
(getSlicedAddress as vi.Mock).mockReturnValue(
(getSlicedAddress as Mock).mockReturnValue(
mockGetSlicedAddress(testAddressComponentAddress),
);

Expand All @@ -65,7 +65,7 @@ describe('Address component', () => {

it('renders the sliced address when address supplied to Identity', () => {
useIdentityContextMock.mockReturnValue({});
(getSlicedAddress as vi.Mock).mockReturnValue(
(getSlicedAddress as Mock).mockReturnValue(
mockGetSlicedAddress(testAddressComponentAddress),
);

Expand All @@ -79,7 +79,7 @@ describe('Address component', () => {

it('displays sliced address when ENS name is not available and isSliced is set to true', () => {
useIdentityContextMock.mockReturnValue({});
(getSlicedAddress as vi.Mock).mockReturnValue(
(getSlicedAddress as Mock).mockReturnValue(
mockGetSlicedAddress(testAddressComponentAddress),
);

Expand Down
4 changes: 2 additions & 2 deletions src/identity/components/Avatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { base, baseSepolia, optimism } from 'viem/chains';
import { vi } from 'vitest';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import '@testing-library/jest-dom';
import { render, screen, waitFor } from '@testing-library/react';
import { useOnchainKit } from '../../useOnchainKit';
Expand All @@ -11,7 +11,7 @@ import { Badge } from './Badge';
import { useIdentityContext } from './IdentityProvider';

function mock<T>(func: T) {
return func as vi.Mock;
return func as Mock;
}

const silenceError = () => {
Expand Down
1 change: 1 addition & 0 deletions src/identity/components/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { describe, expect, it } from 'vitest';
import { Badge } from './Badge';

describe('Badge Component', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/identity/components/DisplayBadge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { useOnchainKit } from '../../useOnchainKit';
Expand All @@ -7,7 +8,7 @@ import { DisplayBadge } from './DisplayBadge';
import { useIdentityContext } from './IdentityProvider';

function mock<T>(func: T) {
return func as vi.Mock;
return func as Mock;
}

vi.mock('../../useOnchainKit', () => ({
Expand Down
10 changes: 5 additions & 5 deletions src/identity/components/EthBalance.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { vi } from 'vitest';
import { type Mock, describe, expect, it, vi } from 'vitest';
import { getRoundedAmount } from '../../internal/utils/getRoundedAmount';
import { useGetETHBalance } from '../../wallet/hooks/useGetETHBalance';
import { EthBalance } from './EthBalance';
import { useIdentityContext } from './IdentityProvider';

function mock<T>(func: T) {
return func as vi.Mock;
return func as Mock;
}

const silenceError = () => {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('EthBalance', () => {
convertedBalance: balance,
error: null,
});
(getRoundedAmount as vi.Mock).mockReturnValue('1.2346');
(getRoundedAmount as Mock).mockReturnValue('1.2346');

render(
<EthBalance
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('EthBalance', () => {
convertedBalance: balance,
error: null,
});
(getRoundedAmount as vi.Mock).mockReturnValue('1.2346');
(getRoundedAmount as Mock).mockReturnValue('1.2346');

render(<EthBalance className="custom-class" />);

Expand All @@ -109,7 +109,7 @@ describe('EthBalance', () => {
convertedBalance: balance,
error: null,
});
(getRoundedAmount as vi.Mock).mockReturnValue('1.2346');
(getRoundedAmount as Mock).mockReturnValue('1.2346');

render(
<EthBalance
Expand Down
4 changes: 2 additions & 2 deletions src/identity/components/Identity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import '@testing-library/jest-dom';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { useGetETHBalance } from '../../wallet/hooks/useGetETHBalance';
Expand All @@ -11,7 +11,7 @@ import { Identity } from './Identity';
import { Name } from './Name';

function mock<T>(func: T) {
return func as vi.Mock;
return func as Mock;
}

vi.mock('../hooks/useAvatar', () => ({
Expand Down
1 change: 1 addition & 0 deletions src/identity/components/IdentityLayout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@testing-library/jest-dom';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { Address } from './Address';
import { Avatar } from './Avatar';
import { EthBalance } from './EthBalance';
Expand Down
Loading

0 comments on commit 0435fa0

Please sign in to comment.