Skip to content

Commit

Permalink
test(Input): clearIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyunhe committed Apr 17, 2024
1 parent 8286555 commit 0c1fd22
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/components/input/tests/input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { createRef } from 'react'
import { render, fireEvent, act, userEvent, waitFor, screen } from 'testing'
import { act, fireEvent, render, screen, userEvent, waitFor } from 'testing'
import Input from '..'
import ConfigProvider from '../../config-provider'
import { InputRef } from '../input'

jest.mock('../../../utils/validate', () => ({
Expand Down Expand Up @@ -208,4 +209,40 @@ describe('Input', () => {

expect(input.value).toBe('012')
})

describe('clearIcon', () => {
it('default', () => {
const { baseElement } = render(<Input value='foobar' clearable />)

act(() => {
document.querySelector('input')?.focus()
})

expect(baseElement.querySelector('.antd-mobile-icon')).toBeTruthy()
})

it('custom', () => {
render(<Input value='foobar' clearable clearIcon='bamboo' />)

act(() => {
document.querySelector('input')?.focus()
})

expect(screen.getByText('bamboo')).toBeVisible()
})

it('context', () => {
render(
<ConfigProvider input={{ clearIcon: 'little' }}>
<Input value='foobar' clearable />
</ConfigProvider>
)

act(() => {
document.querySelector('input')?.focus()
})

expect(screen.getByText('little')).toBeVisible()
})
})
})

0 comments on commit 0c1fd22

Please sign in to comment.