rescript-vitest-extras 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +16 -0
- package/README.md +187 -0
- package/package.json +47 -0
- package/rescript.json +34 -0
- package/src/VitestExtras.res +8 -0
- package/src/VitestExtras__Assert.res +627 -0
- package/src/VitestExtras__Assert.resi +302 -0
- package/src/VitestExtras__BrowserExpect.res +159 -0
- package/src/VitestExtras__BrowserExpect.resi +159 -0
- package/src/VitestExtras__BrowserLocator.res +190 -0
- package/src/VitestExtras__BrowserLocator.resi +190 -0
- package/src/VitestExtras__BrowserPage.res +119 -0
- package/src/VitestExtras__BrowserPage.resi +62 -0
- package/src/VitestExtras__BrowserReact.res +201 -0
- package/src/VitestExtras__BrowserReact.resi +201 -0
- package/src/VitestExtras__BrowserUserEvent.res +200 -0
- package/src/VitestExtras__BrowserUserEvent.resi +109 -0
- package/src/VitestExtras__Mock.res +639 -0
- package/src/VitestExtras__Mock.resi +432 -0
- package/src/VitestExtras__MockExpect.res +455 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest Browser UserEvent API bindings.
|
|
3
|
+
*
|
|
4
|
+
* These bindings wrap Vitest's browser-mode `userEvent` singleton with ergonomic
|
|
5
|
+
* ReScript types. Each function below uses the default global `userEvent` instance
|
|
6
|
+
* imported from `vitest/browser`.
|
|
7
|
+
*
|
|
8
|
+
* For an independent instance, call `setup()` to obtain a fresh `t`.
|
|
9
|
+
*/
|
|
10
|
+
/** Opaque type for a UserEvent instance from `vitest/browser`. */
|
|
11
|
+
type t
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Setup
|
|
15
|
+
// =============================================================================
|
|
16
|
+
|
|
17
|
+
/** Creates a new, independent UserEvent instance. */
|
|
18
|
+
let setup: unit => t
|
|
19
|
+
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// Click Operations
|
|
22
|
+
// =============================================================================
|
|
23
|
+
|
|
24
|
+
/** Clicks the given element. */
|
|
25
|
+
let click: (~options: {..}=?, VitestExtras__BrowserLocator.t) => promise<unit>
|
|
26
|
+
|
|
27
|
+
/** Double-clicks the given element. */
|
|
28
|
+
let dblClick: (~options: {..}=?, VitestExtras__BrowserLocator.t) => promise<unit>
|
|
29
|
+
|
|
30
|
+
/** Triple-clicks the given element. */
|
|
31
|
+
let tripleClick: (~options: {..}=?, VitestExtras__BrowserLocator.t) => promise<unit>
|
|
32
|
+
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// Input Operations
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
/** Sets the value of an input element. Unlike `type_`, this does not simulate
|
|
38
|
+
individual keystrokes and has no options parameter. */
|
|
39
|
+
let fill: (VitestExtras__BrowserLocator.t, string) => promise<unit>
|
|
40
|
+
|
|
41
|
+
/** Types text into the given element character by character, simulating real keyboard input.
|
|
42
|
+
Named `type_` because `type` is a reserved word in ReScript. */
|
|
43
|
+
let type_: (~options: {..}=?, VitestExtras__BrowserLocator.t, string) => promise<unit>
|
|
44
|
+
|
|
45
|
+
/** Clears the value of the given input element. */
|
|
46
|
+
let clear: (~options: {..}=?, VitestExtras__BrowserLocator.t) => promise<unit>
|
|
47
|
+
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// Keyboard
|
|
50
|
+
// =============================================================================
|
|
51
|
+
|
|
52
|
+
/** Sends keyboard input without targeting a specific element.
|
|
53
|
+
Uses the same key syntax as `@testing-library/user-event`
|
|
54
|
+
(e.g., `"{Enter}"`, `"{Shift>}A{/Shift}"`). */
|
|
55
|
+
let keyboard: string => promise<unit>
|
|
56
|
+
|
|
57
|
+
/** Presses the Tab key, optionally with modifier options (e.g., `{"shift": true}`). */
|
|
58
|
+
let tab: (~options: {..}=?) => promise<unit>
|
|
59
|
+
|
|
60
|
+
// =============================================================================
|
|
61
|
+
// Hover
|
|
62
|
+
// =============================================================================
|
|
63
|
+
|
|
64
|
+
/** Hovers over the given element. */
|
|
65
|
+
let hover: (~options: {..}=?, VitestExtras__BrowserLocator.t) => promise<unit>
|
|
66
|
+
|
|
67
|
+
/** Moves the pointer away from the given element. */
|
|
68
|
+
let unhover: (~options: {..}=?, VitestExtras__BrowserLocator.t) => promise<unit>
|
|
69
|
+
|
|
70
|
+
// =============================================================================
|
|
71
|
+
// Selection
|
|
72
|
+
// =============================================================================
|
|
73
|
+
|
|
74
|
+
/** Selects the given option(s) in a `<select>` element. The `values` parameter is
|
|
75
|
+
intentionally polymorphic to support `string`, `array<string>`, `Locator`,
|
|
76
|
+
`array<Locator>`, `Dom.element`, or `array<Dom.element>`. */
|
|
77
|
+
let selectOptions: (~options: {..}=?, VitestExtras__BrowserLocator.t, 'a) => promise<unit>
|
|
78
|
+
|
|
79
|
+
// =============================================================================
|
|
80
|
+
// File Upload
|
|
81
|
+
// =============================================================================
|
|
82
|
+
|
|
83
|
+
/** Uploads file(s) to an input element. The `files` parameter is intentionally
|
|
84
|
+
polymorphic to support `string`, `array<string>`, `File`, or `array<File>`. */
|
|
85
|
+
let upload: (~options: {..}=?, VitestExtras__BrowserLocator.t, 'a) => promise<unit>
|
|
86
|
+
|
|
87
|
+
// =============================================================================
|
|
88
|
+
// Drag and Drop
|
|
89
|
+
// =============================================================================
|
|
90
|
+
|
|
91
|
+
/** Drags the source element and drops it onto the target element. */
|
|
92
|
+
let dragAndDrop: (
|
|
93
|
+
~options: {..}=?,
|
|
94
|
+
VitestExtras__BrowserLocator.t,
|
|
95
|
+
VitestExtras__BrowserLocator.t,
|
|
96
|
+
) => promise<unit>
|
|
97
|
+
|
|
98
|
+
// =============================================================================
|
|
99
|
+
// Clipboard
|
|
100
|
+
// =============================================================================
|
|
101
|
+
|
|
102
|
+
/** Copies the current selection to the clipboard. */
|
|
103
|
+
let copy: unit => promise<unit>
|
|
104
|
+
|
|
105
|
+
/** Cuts the current selection to the clipboard. */
|
|
106
|
+
let cut: unit => promise<unit>
|
|
107
|
+
|
|
108
|
+
/** Pastes the clipboard contents at the current cursor position. */
|
|
109
|
+
let paste: unit => promise<unit>
|