Skip to content

Commit 33e3ca3

Browse files
test: address review feedback on Tier 2 test suite
- Rename misleading test names in BigNumberInput (onError absence test, maxUint256 constraint test) - Add beforeEach mock clear in HashInput to prevent cross-test contamination from unconsumed mockResolvedValueOnce calls - Add debounceTime: 0 to clear test to avoid real-timer dependency - Rename debounce test to accurately describe what it covers; fake-timer debounce testing conflicts with waitFor + userEvent in jsdom
1 parent 55510e5 commit 33e3ca3

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/components/sharedComponents/BigNumberInput.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('BigNumberInput', () => {
9494
expect(onError).toHaveBeenCalledWith(expect.objectContaining({ value: '5' }))
9595
})
9696

97-
it('calls onError(null) is NOT called for valid values (no error clearing tested via absence)', async () => {
97+
it('does not call onError for valid values', async () => {
9898
const onError = vi.fn()
9999
renderInput({ decimals: 0, max: BigInt(100), onError })
100100
const input = screen.getByRole('textbox')
@@ -114,11 +114,10 @@ describe('BigNumberInput', () => {
114114
expect(lastCall).toBe(BigInt(112))
115115
})
116116

117-
it('does not update on maxUint256 overflow', async () => {
117+
it('does not call onError when value is within max constraint', async () => {
118118
const onError = vi.fn()
119119
renderInput({ decimals: 0, max: maxUint256, onError })
120-
// Typing an absurdly large number won't overflow since max = maxUint256
121-
// Just verify no onError for normal large numbers
120+
// Large but valid number — well within maxUint256, so no error
122121
const input = screen.getByRole('textbox')
123122
await userEvent.type(input, '9999999')
124123
expect(onError).not.toHaveBeenCalled()

src/components/sharedComponents/HashInput.test.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react'
22
import { render, screen, waitFor } from '@testing-library/react'
33
import userEvent from '@testing-library/user-event'
44
import { mainnet } from 'viem/chains'
5-
import { describe, expect, it, vi } from 'vitest'
5+
import { beforeEach, describe, expect, it, vi } from 'vitest'
66
import HashInput from './HashInput'
77

88
const system = createSystem(defaultConfig)
@@ -27,6 +27,11 @@ function renderHashInput(props: Partial<React.ComponentProps<typeof HashInput>>
2727
}
2828

2929
describe('HashInput', () => {
30+
beforeEach(() => {
31+
detectHashMock.mockClear()
32+
detectHashMock.mockResolvedValue({ type: 'EOA', data: '0xabc' })
33+
})
34+
3035
it('renders without crashing', () => {
3136
const { input } = renderHashInput()
3237
expect(input).not.toBeNull()
@@ -52,15 +57,18 @@ describe('HashInput', () => {
5257

5358
it('calls onSearch with null when input is cleared', async () => {
5459
const onSearch = vi.fn()
55-
const { input } = renderHashInput({ onSearch })
60+
// debounceTime: 0 to avoid relying on real timers for non-debounce behavior
61+
const { input } = renderHashInput({ onSearch, debounceTime: 0 })
5662
await userEvent.type(input, 'abc')
5763
await userEvent.clear(input)
5864
await waitFor(() => {
5965
expect(onSearch).toHaveBeenLastCalledWith(null)
6066
})
6167
})
6268

63-
it('calls onSearch with detection result after debounce', async () => {
69+
it('calls onSearch with the detected result', async () => {
70+
// debounceTime: 0 keeps the test fast; this covers the callback wiring,
71+
// not the debounce delay itself (fake timers + waitFor + userEvent conflict in jsdom)
6472
const onSearch = vi.fn()
6573
detectHashMock.mockResolvedValueOnce({ type: 'ENS', data: '0x123' })
6674
renderHashInput({ onSearch, debounceTime: 0 })

0 commit comments

Comments
 (0)