Skip to content

Commit 41de6eb

Browse files
committed
test: update case
1 parent 83883a4 commit 41de6eb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/packages/backtop/__test__/backtop.spec.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as React from 'react'
33
import '@testing-library/jest-dom'
44
import { Top } from '@nutui/icons-react'
5-
import { render, fireEvent, waitFor, act } from '@testing-library/react'
5+
import { act, fireEvent, render, waitFor } from '@testing-library/react'
66
import BackTop from '@/packages/backtop'
77

88
test('backtop props test', () => {
@@ -52,22 +52,30 @@ test('backtop custom test', () => {
5252

5353
test('scroll', async () => {
5454
const { container } = render(
55-
<div id="target" style={{ height: '100vh' }} className="backtop-wrapper">
55+
<div id="target" style={{ height: '100px' }} className="backtop-wrapper">
5656
{new Array(24).fill(0).map((_, index) => {
57-
return <div key={index}>我是测试数据{index}</div>
57+
return (
58+
<div key={index} style={{ height: 30 }}>
59+
我是测试数据{index}
60+
</div>
61+
)
5862
})}
5963
<BackTop target="target" className="backtop-button" />
6064
</div>
6165
)
6266
const track = container.querySelector('.backtop-wrapper')
63-
const element18 = container.querySelectorAll('.backtop-button')[0]
67+
const element18 = container.querySelectorAll(
68+
'.nut-hoverbutton-item-container'
69+
)[0]
70+
const element19 = container.querySelectorAll('.nut-hoverbutton-container')[0]
6471
if (track) {
72+
track.scrollTo = vi.fn()
6573
track.scrollTop = 200
6674
act(() => {
6775
track.dispatchEvent(new Event('scroll'))
6876
})
6977
await waitFor(() => {
70-
expect(element18).toHaveClass('nut-backtop-show')
78+
expect(element19).toHaveClass('nut-backtop-show')
7179
})
7280
fireEvent.click(element18 as Element)
7381
}

0 commit comments

Comments
 (0)