Skip to content

Commit

Permalink
test(Dropdown.Item): add Dropdown.Item click test
Browse files Browse the repository at this point in the history
  • Loading branch information
liqiuqiui committed Dec 13, 2023
1 parent 24778d3 commit 23450fc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/components/dropdown/tests/dropdown.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'
import { fireEvent, render, screen, waitFor } from 'testing'
import Dropdown from '..'

Expand Down Expand Up @@ -83,4 +83,28 @@ describe('Dropdown', () => {
)
expect(screen.getByText('content')).toBeInTheDocument()
})

test('trigger the click of Dropdown.Item ', () => {
const ClickTest = () => {
const [count, setCount] = useState(0)
return (
<Dropdown>
<Dropdown.Item
onClick={() => setCount(count + 1)}
title='sorter'
key='sorter'
>
click{count}
</Dropdown.Item>
</Dropdown>
)
}

render(<ClickTest />)

fireEvent.click(screen.getByText('sorter'))
expect(screen.getByText('click1'))
fireEvent.click(screen.getByText('sorter'))
expect(screen.getByText('click2'))
})
})

0 comments on commit 23450fc

Please sign in to comment.