Skip to content

Commit 9f5b773

Browse files
test(transaction-button): replace web3Status undefined cast with valid stub
1 parent f1a8adc commit 9f5b773

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/components/sharedComponents/TransactionButton.test.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react'
22
import { render, screen } from '@testing-library/react'
33
import { createElement, type ReactNode } from 'react'
44
import { beforeEach, describe, expect, it, vi } from 'vitest'
5+
import type { Web3Status } from '@/src/hooks/useWeb3Status'
56
import TransactionButton from './TransactionButton'
67

78
const mockSwitchChain = vi.fn()
@@ -43,6 +44,21 @@ vi.mock('wagmi', () => ({
4344
const { useWalletStatus } = await import('@/src/hooks/useWalletStatus')
4445
const mockedUseWalletStatus = vi.mocked(useWalletStatus)
4546

47+
const mockWeb3Status = {
48+
readOnlyClient: undefined,
49+
appChainId: 1,
50+
address: '0xdeadbeef',
51+
balance: undefined,
52+
connectingWallet: false,
53+
switchingChain: false,
54+
isWalletConnected: true,
55+
walletClient: undefined,
56+
isWalletSynced: true,
57+
walletChainId: 1,
58+
switchChain: vi.fn(),
59+
disconnect: vi.fn(),
60+
} as unknown as Web3Status
61+
4662
const system = createSystem(defaultConfig)
4763

4864
const renderWithChakra = (ui: ReactNode) =>
@@ -61,7 +77,7 @@ describe('TransactionButton', () => {
6177
targetChain: { id: 1, name: 'Ethereum' } as ReturnType<typeof useWalletStatus>['targetChain'],
6278
targetChainId: 1,
6379
switchChain: mockSwitchChain,
64-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
80+
web3Status: mockWeb3Status,
6581
})
6682

6783
renderWithChakra(<TransactionButton transaction={mockTransaction}>Send</TransactionButton>)
@@ -78,7 +94,7 @@ describe('TransactionButton', () => {
7894
targetChain: { id: 1, name: 'Ethereum' } as ReturnType<typeof useWalletStatus>['targetChain'],
7995
targetChainId: 1,
8096
switchChain: mockSwitchChain,
81-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
97+
web3Status: mockWeb3Status,
8298
})
8399

84100
renderWithChakra(
@@ -104,7 +120,7 @@ describe('TransactionButton', () => {
104120
>['targetChain'],
105121
targetChainId: 10,
106122
switchChain: mockSwitchChain,
107-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
123+
web3Status: mockWeb3Status,
108124
})
109125

110126
renderWithChakra(<TransactionButton transaction={mockTransaction}>Send</TransactionButton>)
@@ -124,7 +140,7 @@ describe('TransactionButton', () => {
124140
>['targetChain'],
125141
targetChainId: 10,
126142
switchChain: mockSwitchChain,
127-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
143+
web3Status: mockWeb3Status,
128144
})
129145

130146
renderWithChakra(
@@ -148,7 +164,7 @@ describe('TransactionButton', () => {
148164
targetChain: { id: 1, name: 'Ethereum' } as ReturnType<typeof useWalletStatus>['targetChain'],
149165
targetChainId: 1,
150166
switchChain: mockSwitchChain,
151-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
167+
web3Status: mockWeb3Status,
152168
})
153169

154170
renderWithChakra(<TransactionButton transaction={mockTransaction}>Send ETH</TransactionButton>)

0 commit comments

Comments
 (0)