|
1 | 1 | import { SerializedConfig } from 'vitest' |
2 | | -import { StringifyOptions, BrowserCommands } from 'vitest/internal/browser' |
| 2 | +import { AtLeastOneOf, ExactlyOneOf, StringifyOptions, BrowserCommands } from 'vitest/internal/browser' |
3 | 3 | import { ARIARole } from './aria-role.js' |
4 | 4 | import {} from './matchers.js' |
5 | 5 |
|
@@ -207,6 +207,24 @@ export interface UserEvent { |
207 | 207 | * @see {@link https://testing-library.com/docs/user-event/convenience/#tripleclick} testing-library API |
208 | 208 | */ |
209 | 209 | tripleClick: (element: Element | Locator, options?: UserEventTripleClickOptions) => Promise<void> |
| 210 | + /** |
| 211 | + * Triggers a wheel event on an element. |
| 212 | + * |
| 213 | + * @param element - The target element to receive wheel events. |
| 214 | + * @param options - Scroll configuration using `delta` or `direction`. |
| 215 | + * @returns A promise that resolves when all wheel events have been dispatched. |
| 216 | + * |
| 217 | + * @see {@link https://vitest.dev/api/browser/interactivity#userevent-wheel} |
| 218 | + * |
| 219 | + * @example |
| 220 | + * // Scroll down by 100 pixels |
| 221 | + * await userEvent.wheel(container, { delta: { y: 100 } }) |
| 222 | + * |
| 223 | + * @example |
| 224 | + * // Scroll up 5 times |
| 225 | + * await userEvent.wheel(container, { direction: 'up', times: 5 }) |
| 226 | + */ |
| 227 | + wheel(element: Element | Locator, options: UserEventWheelOptions): Promise<void> |
210 | 228 | /** |
211 | 229 | * Choose one or more values from a select element. Uses provider's API under the hood. |
212 | 230 | * If select doesn't have `multiple` attribute, only the first value will be selected. |
@@ -344,6 +362,35 @@ export interface UserEventDoubleClickOptions {} |
344 | 362 | export interface UserEventTripleClickOptions {} |
345 | 363 | export interface UserEventDragAndDropOptions {} |
346 | 364 | export interface UserEventUploadOptions {} |
| 365 | +/** |
| 366 | + * Options for triggering wheel events. |
| 367 | + * |
| 368 | + * Specify scrolling using either `delta` for precise pixel values, or `direction` for semantic scrolling. These are mutually exclusive. |
| 369 | + */ |
| 370 | +export type UserEventWheelOptions = ExactlyOneOf< |
| 371 | + { |
| 372 | + /** |
| 373 | + * Precise scroll delta values in pixels. At least one axis must be specified. |
| 374 | + * |
| 375 | + * - Positive `y` scrolls down, negative `y` scrolls up. |
| 376 | + * - Positive `x` scrolls right, negative `x` scrolls left. |
| 377 | + */ |
| 378 | + delta: AtLeastOneOf<{ x: number, y: number }>, |
| 379 | + /** |
| 380 | + * Semantic scroll direction. Use this for readable tests when exact pixel values don't matter. |
| 381 | + */ |
| 382 | + direction: 'up' | 'down' | 'left' | 'right', |
| 383 | + /** |
| 384 | + * Number of wheel events to fire. Defaults to `1`. |
| 385 | + * |
| 386 | + * Useful for triggering multiple scroll steps in a single call. |
| 387 | + */ |
| 388 | + times?: number, |
| 389 | + }, |
| 390 | + 'delta' | 'direction' |
| 391 | +> |
| 392 | + |
| 393 | +export type UserEventWheelOptionsWithDelta = Extract<UserEventWheelOptions, { delta: { x?: number; y?: number } }> |
347 | 394 |
|
348 | 395 | export interface LocatorOptions { |
349 | 396 | /** |
@@ -489,6 +536,24 @@ export interface Locator extends LocatorSelectors { |
489 | 536 | * @see {@link https://vitest.dev/api/browser/interactivity#userevent-tripleclick} |
490 | 537 | */ |
491 | 538 | tripleClick(options?: UserEventTripleClickOptions): Promise<void> |
| 539 | + /** |
| 540 | + * Triggers a wheel event on an element. |
| 541 | + * |
| 542 | + * @param element - The target element to receive wheel events. |
| 543 | + * @param options - Scroll configuration using `delta` or `direction`. |
| 544 | + * @returns A promise that resolves when all wheel events have been dispatched. |
| 545 | + * |
| 546 | + * @see {@link https://vitest.dev/api/browser/interactivity#userevent-wheel} |
| 547 | + * |
| 548 | + * @example |
| 549 | + * // Scroll down by 100 pixels |
| 550 | + * await container.wheel({ delta: { y: 100 } }) |
| 551 | + * |
| 552 | + * @example |
| 553 | + * // Scroll up 5 times |
| 554 | + * await container.wheel({ direction: 'up', times: 5 }) |
| 555 | + */ |
| 556 | + wheel(options: UserEventWheelOptions): Promise<void> |
492 | 557 | /** |
493 | 558 | * Clears the input element content |
494 | 559 | * @see {@link https://vitest.dev/api/browser/interactivity#userevent-clear} |
|
0 commit comments