Skip to content

Commit d8c5ae2

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

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/components/sharedComponents/SignButton.test.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react'
33
import type { ReactNode } from 'react'
44
import { createElement } from 'react'
55
import { beforeEach, describe, expect, it, vi } from 'vitest'
6+
import type { Web3Status } from '@/src/hooks/useWeb3Status'
67
import SignButton from './SignButton'
78

89
const mockSwitchChain = vi.fn()
@@ -45,6 +46,21 @@ vi.mock('wagmi', () => ({
4546
const { useWalletStatus } = await import('@/src/hooks/useWalletStatus')
4647
const mockedUseWalletStatus = vi.mocked(useWalletStatus)
4748

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

5066
const renderWithChakra = (ui: ReactNode) =>
@@ -63,7 +79,7 @@ describe('SignButton', () => {
6379
targetChain: { id: 1, name: 'Ethereum' } as ReturnType<typeof useWalletStatus>['targetChain'],
6480
targetChainId: 1,
6581
switchChain: mockSwitchChain,
66-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
82+
web3Status: mockWeb3Status,
6783
})
6884

6985
renderWithChakra(<SignButton message="Hello" />)
@@ -80,7 +96,7 @@ describe('SignButton', () => {
8096
targetChain: { id: 1, name: 'Ethereum' } as ReturnType<typeof useWalletStatus>['targetChain'],
8197
targetChainId: 1,
8298
switchChain: mockSwitchChain,
83-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
99+
web3Status: mockWeb3Status,
84100
})
85101

86102
renderWithChakra(
@@ -104,7 +120,7 @@ describe('SignButton', () => {
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(<SignButton message="Hello" />)
@@ -122,7 +138,7 @@ describe('SignButton', () => {
122138
targetChain: { id: 1, name: 'Ethereum' } as ReturnType<typeof useWalletStatus>['targetChain'],
123139
targetChainId: 1,
124140
switchChain: mockSwitchChain,
125-
web3Status: undefined as unknown as ReturnType<typeof useWalletStatus>['web3Status'],
141+
web3Status: mockWeb3Status,
126142
})
127143

128144
renderWithChakra(<SignButton message="Hello" />)

0 commit comments

Comments
 (0)