|
2 | 2 | import * as React from 'react' |
3 | 3 | import '@testing-library/jest-dom' |
4 | 4 | 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' |
6 | 6 | import BackTop from '@/packages/backtop' |
7 | 7 |
|
8 | 8 | test('backtop props test', () => { |
@@ -52,22 +52,30 @@ test('backtop custom test', () => { |
52 | 52 |
|
53 | 53 | test('scroll', async () => { |
54 | 54 | const { container } = render( |
55 | | - <div id="target" style={{ height: '100vh' }} className="backtop-wrapper"> |
| 55 | + <div id="target" style={{ height: '100px' }} className="backtop-wrapper"> |
56 | 56 | {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 | + ) |
58 | 62 | })} |
59 | 63 | <BackTop target="target" className="backtop-button" /> |
60 | 64 | </div> |
61 | 65 | ) |
62 | 66 | 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] |
64 | 71 | if (track) { |
| 72 | + track.scrollTo = vi.fn() |
65 | 73 | track.scrollTop = 200 |
66 | 74 | act(() => { |
67 | 75 | track.dispatchEvent(new Event('scroll')) |
68 | 76 | }) |
69 | 77 | await waitFor(() => { |
70 | | - expect(element18).toHaveClass('nut-backtop-show') |
| 78 | + expect(element19).toHaveClass('nut-backtop-show') |
71 | 79 | }) |
72 | 80 | fireEvent.click(element18 as Element) |
73 | 81 | } |
|
0 commit comments