@vitest-agent/mcp 1.0.1 → 1.2.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.
Files changed (229) hide show
  1. package/README.md +1 -2
  2. package/bin/vitest-agent-mcp.js +1 -17
  3. package/index.d.ts +324 -315
  4. package/index.js +2 -4
  5. package/middleware/idempotency.js +1 -1
  6. package/package.json +2 -2
  7. package/server.js +2 -4
  8. package/tools/acceptance-metrics.js +1 -1
  9. package/tools/cache-health.js +1 -1
  10. package/tools/commit-changes.js +1 -1
  11. package/tools/configure.js +1 -1
  12. package/tools/coverage.js +1 -1
  13. package/tools/errors.js +1 -1
  14. package/tools/failure-signature-get.js +1 -1
  15. package/tools/file-coverage.js +1 -1
  16. package/tools/history.js +1 -1
  17. package/tools/inventory.js +1 -1
  18. package/tools/overview.js +1 -1
  19. package/tools/run-tests.js +15 -3
  20. package/tools/settings-list.js +1 -1
  21. package/tools/status.js +1 -1
  22. package/tools/tdd-artifact.js +1 -1
  23. package/tools/tdd-task.js +1 -1
  24. package/tools/test.js +1 -1
  25. package/tools/trends.js +1 -1
  26. package/tools/turn-search.js +1 -1
  27. package/public/patterns/_meta.json +0 -67
  28. package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
  29. package/public/patterns/known-issues-and-caveats.md +0 -52
  30. package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
  31. package/public/patterns/running-tests-via-mcp.md +0 -58
  32. package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
  33. package/public/patterns/testing-effect-schema-definitions.md +0 -71
  34. package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
  35. package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
  36. package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
  37. package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
  38. package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
  39. package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
  40. package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
  41. package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
  42. package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
  43. package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
  44. package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
  45. package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
  46. package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
  47. package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
  48. package/public/vendor/vitest-docs/api/assert-type.md +0 -22
  49. package/public/vendor/vitest-docs/api/assert.md +0 -1960
  50. package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
  51. package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
  52. package/public/vendor/vitest-docs/api/browser/context.md +0 -338
  53. package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
  54. package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
  55. package/public/vendor/vitest-docs/api/browser/react.md +0 -346
  56. package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
  57. package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
  58. package/public/vendor/vitest-docs/api/describe.md +0 -374
  59. package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
  60. package/public/vendor/vitest-docs/api/expect.md +0 -2304
  61. package/public/vendor/vitest-docs/api/hooks.md +0 -463
  62. package/public/vendor/vitest-docs/api/mock.md +0 -701
  63. package/public/vendor/vitest-docs/api/test.md +0 -926
  64. package/public/vendor/vitest-docs/api/vi.md +0 -1372
  65. package/public/vendor/vitest-docs/config/alias.md +0 -13
  66. package/public/vendor/vitest-docs/config/allowonly.md +0 -32
  67. package/public/vendor/vitest-docs/config/api.md +0 -27
  68. package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
  69. package/public/vendor/vitest-docs/config/bail.md +0 -9
  70. package/public/vendor/vitest-docs/config/benchmark.md +0 -65
  71. package/public/vendor/vitest-docs/config/browser/api.md +0 -23
  72. package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
  73. package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
  74. package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
  75. package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
  76. package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
  77. package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
  78. package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
  79. package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
  80. package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
  81. package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
  82. package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
  83. package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
  84. package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
  85. package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
  86. package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
  87. package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
  88. package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
  89. package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
  90. package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
  91. package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
  92. package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
  93. package/public/vendor/vitest-docs/config/cache.md +0 -26
  94. package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
  95. package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
  96. package/public/vendor/vitest-docs/config/coverage.md +0 -455
  97. package/public/vendor/vitest-docs/config/css.md +0 -47
  98. package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
  99. package/public/vendor/vitest-docs/config/deps.md +0 -127
  100. package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
  101. package/public/vendor/vitest-docs/config/diff.md +0 -96
  102. package/public/vendor/vitest-docs/config/dir.md +0 -7
  103. package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
  104. package/public/vendor/vitest-docs/config/env.md +0 -5
  105. package/public/vendor/vitest-docs/config/environment.md +0 -96
  106. package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
  107. package/public/vendor/vitest-docs/config/exclude.md +0 -49
  108. package/public/vendor/vitest-docs/config/execargv.md +0 -10
  109. package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
  110. package/public/vendor/vitest-docs/config/expect.md +0 -38
  111. package/public/vendor/vitest-docs/config/experimental.md +0 -510
  112. package/public/vendor/vitest-docs/config/faketimers.md +0 -51
  113. package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
  114. package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
  115. package/public/vendor/vitest-docs/config/globals.md +0 -42
  116. package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
  117. package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
  118. package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
  119. package/public/vendor/vitest-docs/config/include-source.md +0 -115
  120. package/public/vendor/vitest-docs/config/include.md +0 -71
  121. package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
  122. package/public/vendor/vitest-docs/config/index.md +0 -85
  123. package/public/vendor/vitest-docs/config/isolate.md +0 -13
  124. package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
  125. package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
  126. package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
  127. package/public/vendor/vitest-docs/config/mockreset.md +0 -22
  128. package/public/vendor/vitest-docs/config/mode.md +0 -7
  129. package/public/vendor/vitest-docs/config/name.md +0 -111
  130. package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
  131. package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
  132. package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
  133. package/public/vendor/vitest-docs/config/open.md +0 -7
  134. package/public/vendor/vitest-docs/config/outputfile.md +0 -7
  135. package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
  136. package/public/vendor/vitest-docs/config/pool.md +0 -45
  137. package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
  138. package/public/vendor/vitest-docs/config/projects.md +0 -6
  139. package/public/vendor/vitest-docs/config/provide.md +0 -45
  140. package/public/vendor/vitest-docs/config/reporters.md +0 -69
  141. package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
  142. package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
  143. package/public/vendor/vitest-docs/config/retry.md +0 -140
  144. package/public/vendor/vitest-docs/config/root.md +0 -6
  145. package/public/vendor/vitest-docs/config/runner.md +0 -6
  146. package/public/vendor/vitest-docs/config/sequence.md +0 -158
  147. package/public/vendor/vitest-docs/config/server.md +0 -68
  148. package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
  149. package/public/vendor/vitest-docs/config/silent.md +0 -9
  150. package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
  151. package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
  152. package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
  153. package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
  154. package/public/vendor/vitest-docs/config/stricttags.md +0 -30
  155. package/public/vendor/vitest-docs/config/tags.md +0 -141
  156. package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
  157. package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
  158. package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
  159. package/public/vendor/vitest-docs/config/typecheck.md +0 -77
  160. package/public/vendor/vitest-docs/config/ui.md +0 -15
  161. package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
  162. package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
  163. package/public/vendor/vitest-docs/config/update.md +0 -16
  164. package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
  165. package/public/vendor/vitest-docs/config/watch.md +0 -11
  166. package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
  167. package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
  168. package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
  169. package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
  170. package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
  171. package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
  172. package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
  173. package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
  174. package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
  175. package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
  176. package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
  177. package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
  178. package/public/vendor/vitest-docs/guide/cli.md +0 -234
  179. package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
  180. package/public/vendor/vitest-docs/guide/coverage.md +0 -515
  181. package/public/vendor/vitest-docs/guide/debugging.md +0 -127
  182. package/public/vendor/vitest-docs/guide/environment.md +0 -101
  183. package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
  184. package/public/vendor/vitest-docs/guide/features.md +0 -310
  185. package/public/vendor/vitest-docs/guide/filtering.md +0 -175
  186. package/public/vendor/vitest-docs/guide/ide.md +0 -43
  187. package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
  188. package/public/vendor/vitest-docs/guide/in-source.md +0 -159
  189. package/public/vendor/vitest-docs/guide/index.md +0 -128
  190. package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
  191. package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
  192. package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
  193. package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
  194. package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
  195. package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
  196. package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
  197. package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
  198. package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
  199. package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
  200. package/public/vendor/vitest-docs/guide/migration.md +0 -863
  201. package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
  202. package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
  203. package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
  204. package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
  205. package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
  206. package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
  207. package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
  208. package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
  209. package/public/vendor/vitest-docs/guide/mocking.md +0 -239
  210. package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
  211. package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
  212. package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
  213. package/public/vendor/vitest-docs/guide/projects.md +0 -291
  214. package/public/vendor/vitest-docs/guide/recipes.md +0 -59
  215. package/public/vendor/vitest-docs/guide/reporters.md +0 -723
  216. package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
  217. package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
  218. package/public/vendor/vitest-docs/guide/test-context.md +0 -902
  219. package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
  220. package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
  221. package/public/vendor/vitest-docs/guide/ui.md +0 -160
  222. package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
  223. package/public/vendor/vitest-docs/manifest.json +0 -1691
  224. package/resources/index.js +0 -166
  225. package/resources/indexes.js +0 -77
  226. package/resources/manifest-schema.js +0 -46
  227. package/resources/paths.js +0 -20
  228. package/resources/patterns.js +0 -22
  229. package/resources/upstream-docs.js +0 -22
@@ -1,681 +0,0 @@
1
- # Interactivity API
2
-
3
- Vitest implements a subset of [`@testing-library/user-event`](https://testing-library.com/docs/user-event/intro) APIs using [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) or [webdriver](https://www.w3.org/TR/webdriver/) instead of faking events which makes the browser behaviour more reliable and consistent with how users interact with a page.
4
-
5
- ```ts
6
- import { userEvent } from 'vitest/browser'
7
-
8
- await userEvent.click(document.querySelector('.button'))
9
- ```
10
-
11
- Almost every `userEvent` method inherits its provider options.
12
-
13
- ## userEvent.setup
14
-
15
- ```ts
16
- function setup(): UserEvent
17
- ```
18
-
19
- Creates a new user event instance. This is useful if you need to keep the state of keyboard to press and release buttons correctly.
20
-
21
- ::: warning
22
- Unlike `@testing-library/user-event`, the default `userEvent` instance from `vitest/browser` is created once, not every time its methods are called! You can see the difference in how it works in this snippet:
23
-
24
- ```ts
25
- import { userEvent as vitestUserEvent } from 'vitest/browser'
26
- import { userEvent as originalUserEvent } from '@testing-library/user-event'
27
-
28
- await vitestUserEvent.keyboard('{Shift}') // press shift without releasing
29
- await vitestUserEvent.keyboard('{/Shift}') // releases shift
30
-
31
- await originalUserEvent.keyboard('{Shift}') // press shift without releasing
32
- await originalUserEvent.keyboard('{/Shift}') // DID NOT release shift because the state is different
33
- ```
34
-
35
- This behaviour is more useful because we do not emulate the keyboard, we actually press the Shift, so keeping the original behaviour would cause unexpected issues when typing in the field.
36
- :::
37
-
38
- ::: warning
39
- With `playwright` and `webdriverio` providers, interactions are performed by the underlying browser driver. That means some interaction state, like pressed keys or pointer position and the resulting hover state, can persist between tests in the same file.
40
-
41
- Vitest resets unreleased keyboard state automatically before starting each test case, but pointer position and the resulting hover state are not reset automatically since resetting pointer position can be expensive.
42
-
43
- This applies both to `userEvent.*` calls and locator shortcuts like `locator.click()` or `locator.hover()`, because they use the same underlying interaction state.
44
-
45
- If your tests depend on a neutral hover state, reset it explicitly, for example in `beforeEach`:
46
-
47
- ```ts
48
- import { beforeEach } from 'vitest'
49
- import { userEvent } from 'vitest/browser'
50
-
51
- beforeEach(async () => {
52
- await userEvent.unhover(document.body)
53
- })
54
- ```
55
- :::
56
-
57
- ## userEvent.click
58
-
59
- ```ts
60
- function click(
61
- element: Element | Locator,
62
- options?: UserEventClickOptions,
63
- ): Promise<void>
64
- ```
65
-
66
- Click on an element. Inherits provider's options. Please refer to your provider's documentation for detailed explanation about how this method works.
67
-
68
- ```ts
69
- import { page, userEvent } from 'vitest/browser'
70
-
71
- test('clicks on an element', async () => {
72
- const logo = page.getByRole('img', { name: /logo/ })
73
-
74
- await userEvent.click(logo)
75
- // or you can access it directly on the locator
76
- await logo.click()
77
-
78
- // With WebdriverIO, this uses either ElementClick (with no arguments) or
79
- // actions (with arguments). Use an empty object to force the use of actions.
80
- await logo.click({})
81
- })
82
- ```
83
-
84
- ### Clicking with a modifier
85
-
86
- With either WebdriverIO or Playwright:
87
-
88
- ```ts
89
- await userEvent.keyboard('{Shift>}')
90
- // By using an empty object as the option, this opts in to using a chain of actions
91
- // instead of an ElementClick in webdriver.
92
- // Firefox has a bug that makes this necessary.
93
- // Follow https://bugzilla.mozilla.org/show_bug.cgi?id=1456642 to know when this
94
- // will be fixed.
95
- await userEvent.click(element, {})
96
- await userEvent.keyboard('{/Shift}')
97
- ```
98
-
99
- With Playwright:
100
- ```ts
101
- await userEvent.click(element, { modifiers: ['Shift'] })
102
- ```
103
-
104
- References:
105
-
106
- - [Playwright `locator.click` API](https://playwright.dev/docs/api/class-locator#locator-click)
107
- - [WebdriverIO `element.click` API](https://webdriver.io/docs/api/element/click/)
108
- - [testing-library `click` API](https://testing-library.com/docs/user-event/convenience/#click)
109
-
110
- ## userEvent.dblClick
111
-
112
- ```ts
113
- function dblClick(
114
- element: Element | Locator,
115
- options?: UserEventDoubleClickOptions,
116
- ): Promise<void>
117
- ```
118
-
119
- Triggers a double click event on an element.
120
-
121
- Please refer to your provider's documentation for detailed explanation about how this method works.
122
-
123
- ```ts
124
- import { page, userEvent } from 'vitest/browser'
125
-
126
- test('triggers a double click on an element', async () => {
127
- const logo = page.getByRole('img', { name: /logo/ })
128
-
129
- await userEvent.dblClick(logo)
130
- // or you can access it directly on the locator
131
- await logo.dblClick()
132
- })
133
- ```
134
-
135
- References:
136
-
137
- - [Playwright `locator.dblclick` API](https://playwright.dev/docs/api/class-locator#locator-dblclick)
138
- - [WebdriverIO `element.doubleClick` API](https://webdriver.io/docs/api/element/doubleClick/)
139
- - [testing-library `dblClick` API](https://testing-library.com/docs/user-event/convenience/#dblClick)
140
-
141
- ## userEvent.tripleClick
142
-
143
- ```ts
144
- function tripleClick(
145
- element: Element | Locator,
146
- options?: UserEventTripleClickOptions,
147
- ): Promise<void>
148
- ```
149
-
150
- Triggers a triple click event on an element. Since there is no `tripleclick` in browser api, this method will fire three click events in a row, and so you must check [click event detail](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event#usage_notes) to filter the event: `evt.detail === 3`.
151
-
152
- Please refer to your provider's documentation for detailed explanation about how this method works.
153
-
154
- ```ts
155
- import { page, userEvent } from 'vitest/browser'
156
-
157
- test('triggers a triple click on an element', async () => {
158
- const logo = page.getByRole('img', { name: /logo/ })
159
- let tripleClickFired = false
160
- logo.addEventListener('click', (evt) => {
161
- if (evt.detail === 3) {
162
- tripleClickFired = true
163
- }
164
- })
165
-
166
- await userEvent.tripleClick(logo)
167
- // or you can access it directly on the locator
168
- await logo.tripleClick()
169
-
170
- expect(tripleClickFired).toBe(true)
171
- })
172
- ```
173
-
174
- References:
175
-
176
- - [Playwright `locator.click` API](https://playwright.dev/docs/api/class-locator#locator-click): implemented via `click` with `clickCount: 3` .
177
- - [WebdriverIO `browser.action` API](https://webdriver.io/docs/api/browser/action/): implemented via actions api with `move` plus three `down + up + pause` events in a row
178
- - [testing-library `tripleClick` API](https://testing-library.com/docs/user-event/convenience/#tripleClick)
179
-
180
- ## userEvent.wheel <Version>4.1.0</Version> {#userevent-wheel}
181
-
182
- ```ts
183
- function wheel(
184
- element: Element | Locator,
185
- options: UserEventWheelOptions,
186
- ): Promise<void>
187
- ```
188
-
189
- Triggers a [`wheel` event](https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event) on an element.
190
-
191
- You can specify the scroll amount using either `delta` for precise pixel-based control, or `direction` for simpler directional scrolling (`up`, `down`, `left`, `right`). When you need to trigger multiple wheel events, use the `times` option rather than calling the method multiple times for better performance.
192
-
193
- ```ts
194
- import { page, userEvent } from 'vitest/browser'
195
-
196
- test('scroll using delta values', async () => {
197
- const tablist = page.getByRole('tablist')
198
-
199
- // Scroll right by 100 pixels
200
- await userEvent.wheel(tablist, { delta: { x: 100 } })
201
-
202
- // Scroll down by 50 pixels
203
- await userEvent.wheel(tablist, { delta: { y: 50 } })
204
-
205
- // Scroll diagonally 2 times
206
- await userEvent.wheel(tablist, { delta: { x: 50, y: 100 }, times: 2 })
207
- })
208
-
209
- test('scroll using direction', async () => {
210
- const tablist = page.getByRole('tablist')
211
-
212
- // Scroll right 5 times
213
- await userEvent.wheel(tablist, { direction: 'right', times: 5 })
214
-
215
- // Scroll left once
216
- await userEvent.wheel(tablist, { direction: 'left' })
217
- })
218
- ```
219
-
220
- Wheel events can also be triggered directly from [locators](/api/browser/locators#wheel):
221
-
222
- ```ts
223
- import { page } from 'vitest/browser'
224
-
225
- await page.getByRole('tablist').wheel({ direction: 'right' })
226
- ```
227
-
228
- ::: warning
229
- This method is intended for testing UI that explicitly listens to `wheel` events (e.g., custom zoom controls, horizontal tab scrolling, canvas interactions). If you need to scroll the page to bring an element into view, rely on the built-in automatic scrolling functionality provided by other `userEvent` methods or [locator actions](/api/browser/locators#methods) instead.
230
- :::
231
-
232
- ## userEvent.fill
233
-
234
- ```ts
235
- function fill(
236
- element: Element | Locator,
237
- text: string,
238
- ): Promise<void>
239
- ```
240
-
241
- Set a value to the `input`/`textarea`/`contenteditable` field. This will remove any existing text in the input before setting the new value.
242
-
243
- ```ts
244
- import { page, userEvent } from 'vitest/browser'
245
-
246
- test('update input', async () => {
247
- const input = page.getByRole('input')
248
-
249
- await userEvent.fill(input, 'foo') // input.value == foo
250
- await userEvent.fill(input, '{{a[[') // input.value == {{a[[
251
- await userEvent.fill(input, '{Shift}') // input.value == {Shift}
252
-
253
- // or you can access it directly on the locator
254
- await input.fill('foo') // input.value == foo
255
- })
256
- ```
257
-
258
- This methods focuses the element, fills it and triggers an `input` event after filling. You can use an empty string to clear the field.
259
-
260
- ::: tip
261
- This API is faster than using [`userEvent.type`](#userevent-type) or [`userEvent.keyboard`](#userevent-keyboard), but it **doesn't support** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}{selectall}`).
262
-
263
- We recommend using this API over [`userEvent.type`](#userevent-type) in situations when you don't need to enter special characters or have granular control over keypress events.
264
- :::
265
-
266
- References:
267
-
268
- - [Playwright `locator.fill` API](https://playwright.dev/docs/api/class-locator#locator-fill)
269
- - [WebdriverIO `element.setValue` API](https://webdriver.io/docs/api/element/setValue)
270
- - [testing-library `type` API](https://testing-library.com/docs/user-event/utility/#type)
271
-
272
- ## userEvent.keyboard
273
-
274
- ```ts
275
- function keyboard(text: string): Promise<void>
276
- ```
277
-
278
- The `userEvent.keyboard` allows you to trigger keyboard strokes. If any input has a focus, it will type characters into that input. Otherwise, it will trigger keyboard events on the currently focused element (`document.body` if there are no focused elements).
279
-
280
- This API supports [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard).
281
-
282
- ```ts
283
- import { userEvent } from 'vitest/browser'
284
-
285
- test('trigger keystrokes', async () => {
286
- await userEvent.keyboard('foo') // translates to: f, o, o
287
- await userEvent.keyboard('{{a[[') // translates to: {, a, [
288
- await userEvent.keyboard('{Shift}{f}{o}{o}') // translates to: Shift, f, o, o
289
- await userEvent.keyboard('{a>5}') // press a without releasing it and trigger 5 keydown
290
- await userEvent.keyboard('{a>5/}') // press a for 5 keydown and then release it
291
- })
292
- ```
293
-
294
- References:
295
-
296
- - [Playwright `Keyboard` API](https://playwright.dev/docs/api/class-keyboard)
297
- - [WebdriverIO `action('key')` API](https://webdriver.io/docs/api/browser/action#key-input-source)
298
- - [testing-library `type` API](https://testing-library.com/docs/user-event/utility/#type)
299
-
300
- ## userEvent.tab
301
-
302
- ```ts
303
- function tab(options?: UserEventTabOptions): Promise<void>
304
- ```
305
-
306
- Sends a `Tab` key event. This is a shorthand for `userEvent.keyboard('{tab}')`.
307
-
308
- ```ts
309
- import { page, userEvent } from 'vitest/browser'
310
-
311
- test('tab works', async () => {
312
- const [input1, input2] = page.getByRole('input').elements()
313
-
314
- expect(input1).toHaveFocus()
315
-
316
- await userEvent.tab()
317
-
318
- expect(input2).toHaveFocus()
319
-
320
- await userEvent.tab({ shift: true })
321
-
322
- expect(input1).toHaveFocus()
323
- })
324
- ```
325
-
326
- References:
327
-
328
- - [Playwright `Keyboard` API](https://playwright.dev/docs/api/class-keyboard)
329
- - [WebdriverIO `action('key')` API](https://webdriver.io/docs/api/browser/action#key-input-source)
330
- - [testing-library `tab` API](https://testing-library.com/docs/user-event/convenience/#tab)
331
-
332
- ## userEvent.type
333
-
334
- ```ts
335
- function type(
336
- element: Element | Locator,
337
- text: string,
338
- options?: UserEventTypeOptions,
339
- ): Promise<void>
340
- ```
341
-
342
- ::: warning
343
- If you don't rely on [special characters](https://testing-library.com/docs/user-event/keyboard) (e.g., `{shift}` or `{selectall}`), it is recommended to use [`userEvent.fill`](#userevent-fill) instead for better performance.
344
- :::
345
-
346
- The `type` method implements `@testing-library/user-event`'s [`type`](https://testing-library.com/docs/user-event/utility/#type) utility built on top of [`keyboard`](https://testing-library.com/docs/user-event/keyboard) API.
347
-
348
- This function allows you to type characters into an `input`/`textarea`/`contenteditable` element. It supports [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard).
349
-
350
- If you just need to press characters without an input, use [`userEvent.keyboard`](#userevent-keyboard) API.
351
-
352
- ```ts
353
- import { page, userEvent } from 'vitest/browser'
354
-
355
- test('update input', async () => {
356
- const input = page.getByRole('input')
357
-
358
- await userEvent.type(input, 'foo') // input.value == foo
359
- await userEvent.type(input, '{{a[[') // input.value == foo{a[
360
- await userEvent.type(input, '{Shift}') // input.value == foo{a[
361
- })
362
- ```
363
-
364
- ::: info
365
- Vitest doesn't expose `.type` method on the locator like `input.type` because it exists only for compatibility with the `userEvent` library. Consider using `.fill` instead as it is faster.
366
- :::
367
-
368
- References:
369
-
370
- - [Playwright `locator.press` API](https://playwright.dev/docs/api/class-locator#locator-press)
371
- - [WebdriverIO `action('key')` API](https://webdriver.io/docs/api/browser/action#key-input-source)
372
- - [testing-library `type` API](https://testing-library.com/docs/user-event/utility/#type)
373
-
374
- ## userEvent.clear
375
-
376
- ```ts
377
- function clear(element: Element | Locator, options?: UserEventClearOptions): Promise<void>
378
- ```
379
-
380
- This method clears the input element content.
381
-
382
- ```ts
383
- import { page, userEvent } from 'vitest/browser'
384
-
385
- test('clears input', async () => {
386
- const input = page.getByRole('input')
387
-
388
- await userEvent.fill(input, 'foo')
389
- expect(input).toHaveValue('foo')
390
-
391
- await userEvent.clear(input)
392
- // or you can access it directly on the locator
393
- await input.clear()
394
-
395
- expect(input).toHaveValue('')
396
- })
397
- ```
398
-
399
- References:
400
-
401
- - [Playwright `locator.clear` API](https://playwright.dev/docs/api/class-locator#locator-clear)
402
- - [WebdriverIO `element.clearValue` API](https://webdriver.io/docs/api/element/clearValue)
403
- - [testing-library `clear` API](https://testing-library.com/docs/user-event/utility/#clear)
404
-
405
- ## userEvent.selectOptions
406
-
407
- ```ts
408
- function selectOptions(
409
- element: Element | Locator,
410
- values:
411
- | HTMLElement
412
- | HTMLElement[]
413
- | Locator
414
- | Locator[]
415
- | string
416
- | string[],
417
- options?: UserEventSelectOptions,
418
- ): Promise<void>
419
- ```
420
-
421
- The `userEvent.selectOptions` allows selecting a value in a `<select>` element.
422
-
423
- ::: warning
424
- If select element doesn't have [`multiple`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attr-multiple) attribute, Vitest will select only the first element in the array.
425
-
426
- Unlike `@testing-library`, Vitest doesn't support [listbox](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role) at the moment, but we plan to add support for it in the future.
427
- :::
428
-
429
- ```ts
430
- import { page, userEvent } from 'vitest/browser'
431
-
432
- test('clears input', async () => {
433
- const select = page.getByRole('select')
434
-
435
- await userEvent.selectOptions(select, 'Option 1')
436
- // or you can access it directly on the locator
437
- await select.selectOptions('Option 1')
438
-
439
- expect(select).toHaveValue('option-1')
440
-
441
- await userEvent.selectOptions(select, 'option-1')
442
- expect(select).toHaveValue('option-1')
443
-
444
- await userEvent.selectOptions(select, [
445
- page.getByRole('option', { name: 'Option 1' }),
446
- page.getByRole('option', { name: 'Option 2' }),
447
- ])
448
- expect(select).toHaveValue(['option-1', 'option-2'])
449
- })
450
- ```
451
-
452
- ::: warning
453
- `webdriverio` provider doesn't support selecting multiple elements because it doesn't provide API to do so.
454
- :::
455
-
456
- References:
457
-
458
- - [Playwright `locator.selectOption` API](https://playwright.dev/docs/api/class-locator#locator-select-option)
459
- - [WebdriverIO `element.selectByIndex` API](https://webdriver.io/docs/api/element/selectByIndex)
460
- - [testing-library `selectOptions` API](https://testing-library.com/docs/user-event/utility/#-selectoptions-deselectoptions)
461
-
462
- ## userEvent.hover
463
-
464
- ```ts
465
- function hover(
466
- element: Element | Locator,
467
- options?: UserEventHoverOptions,
468
- ): Promise<void>
469
- ```
470
-
471
- This method moves the cursor position to the selected element. Please refer to your provider's documentation for detailed explanation about how this method works.
472
-
473
- ::: warning
474
- If you are using `webdriverio` provider, the cursor will move to the center of the element by default.
475
-
476
- If you are using `playwright` provider, the cursor moves to "some" visible point of the element.
477
- :::
478
-
479
- ```ts
480
- import { page, userEvent } from 'vitest/browser'
481
-
482
- test('hovers logo element', async () => {
483
- const logo = page.getByRole('img', { name: /logo/ })
484
-
485
- await userEvent.hover(logo)
486
- // or you can access it directly on the locator
487
- await logo.hover()
488
- })
489
- ```
490
-
491
- References:
492
-
493
- - [Playwright `locator.hover` API](https://playwright.dev/docs/api/class-locator#locator-hover)
494
- - [WebdriverIO `element.moveTo` API](https://webdriver.io/docs/api/element/moveTo/)
495
- - [testing-library `hover` API](https://testing-library.com/docs/user-event/convenience/#hover)
496
-
497
- ## userEvent.unhover
498
-
499
- ```ts
500
- function unhover(
501
- element: Element | Locator,
502
- options?: UserEventHoverOptions,
503
- ): Promise<void>
504
- ```
505
-
506
- This works the same as [`userEvent.hover`](#userevent-hover), but moves the cursor to the `document.body` element instead.
507
-
508
- ::: warning
509
- By default, the cursor position is in "some" visible place (in `playwright` provider) or in the center (in `webdriverio` provider) of the body element, so if the currently hovered element is already in the same position, this method will have no effect.
510
- :::
511
-
512
- ```ts
513
- import { page, userEvent } from 'vitest/browser'
514
-
515
- test('unhover logo element', async () => {
516
- const logo = page.getByRole('img', { name: /logo/ })
517
-
518
- await userEvent.unhover(logo)
519
- // or you can access it directly on the locator
520
- await logo.unhover()
521
- })
522
- ```
523
-
524
- References:
525
-
526
- - [Playwright `locator.hover` API](https://playwright.dev/docs/api/class-locator#locator-hover)
527
- - [WebdriverIO `element.moveTo` API](https://webdriver.io/docs/api/element/moveTo/)
528
- - [testing-library `hover` API](https://testing-library.com/docs/user-event/convenience/#hover)
529
-
530
- ## userEvent.upload
531
-
532
- ```ts
533
- function upload(
534
- element: Element | Locator,
535
- files: string[] | string | File[] | File,
536
- options?: UserEventUploadOptions,
537
- ): Promise<void>
538
- ```
539
-
540
- Change a file input element to have the specified files.
541
-
542
- ```ts
543
- import { page, userEvent } from 'vitest/browser'
544
-
545
- test('can upload a file', async () => {
546
- const input = page.getByRole('button', { name: /Upload files/ })
547
-
548
- const file = new File(['file'], 'file.png', { type: 'image/png' })
549
-
550
- await userEvent.upload(input, file)
551
- // or you can access it directly on the locator
552
- await input.upload(file)
553
-
554
- // you can also use file paths relative to the root of the project
555
- await userEvent.upload(input, './fixtures/file.png')
556
- })
557
- ```
558
-
559
- ::: warning
560
- `webdriverio` provider supports this command only in `chrome` and `edge` browsers. It also only supports string types at the moment.
561
- :::
562
-
563
- References:
564
-
565
- - [Playwright `locator.setInputFiles` API](https://playwright.dev/docs/api/class-locator#locator-set-input-files)
566
- - [WebdriverIO `browser.uploadFile` API](https://webdriver.io/docs/api/browser/uploadFile)
567
- - [testing-library `upload` API](https://testing-library.com/docs/user-event/utility/#upload)
568
-
569
- ## userEvent.dragAndDrop
570
-
571
- ```ts
572
- function dragAndDrop(
573
- source: Element | Locator,
574
- target: Element | Locator,
575
- options?: UserEventDragAndDropOptions,
576
- ): Promise<void>
577
- ```
578
-
579
- Drags the source element on top of the target element. Don't forget that the `source` element has to have the `draggable` attribute set to `true`.
580
-
581
- ```ts
582
- import { page, userEvent } from 'vitest/browser'
583
-
584
- test('drag and drop works', async () => {
585
- const source = page.getByRole('img', { name: /logo/ })
586
- const target = page.getByTestId('logo-target')
587
-
588
- await userEvent.dragAndDrop(source, target)
589
- // or you can access it directly on the locator
590
- await source.dropTo(target)
591
-
592
- await expect.element(target).toHaveTextContent('Logo is processed')
593
- })
594
- ```
595
-
596
- ::: warning
597
- This API is not supported by the default `preview` provider.
598
- :::
599
-
600
- References:
601
-
602
- - [Playwright `frame.dragAndDrop` API](https://playwright.dev/docs/api/class-frame#frame-drag-and-drop)
603
- - [WebdriverIO `element.dragAndDrop` API](https://webdriver.io/docs/api/element/dragAndDrop/)
604
-
605
- ## userEvent.copy
606
-
607
- ```ts
608
- function copy(): Promise<void>
609
- ```
610
-
611
- Copy the selected text to the clipboard.
612
-
613
- ```js
614
- import { page, userEvent } from 'vitest/browser'
615
-
616
- test('copy and paste', async () => {
617
- // write to 'source'
618
- await userEvent.click(page.getByPlaceholder('source'))
619
- await userEvent.keyboard('hello')
620
-
621
- // select and copy 'source'
622
- await userEvent.dblClick(page.getByPlaceholder('source'))
623
- await userEvent.copy()
624
-
625
- // paste to 'target'
626
- await userEvent.click(page.getByPlaceholder('target'))
627
- await userEvent.paste()
628
-
629
- await expect.element(page.getByPlaceholder('source')).toHaveTextContent('hello')
630
- await expect.element(page.getByPlaceholder('target')).toHaveTextContent('hello')
631
- })
632
- ```
633
-
634
- References:
635
-
636
- - [testing-library `copy` API](https://testing-library.com/docs/user-event/convenience/#copy)
637
-
638
- ## userEvent.cut
639
-
640
- ```ts
641
- function cut(): Promise<void>
642
- ```
643
-
644
- Cut the selected text to the clipboard.
645
-
646
- ```js
647
- import { page, userEvent } from 'vitest/browser'
648
-
649
- test('copy and paste', async () => {
650
- // write to 'source'
651
- await userEvent.click(page.getByPlaceholder('source'))
652
- await userEvent.keyboard('hello')
653
-
654
- // select and cut 'source'
655
- await userEvent.dblClick(page.getByPlaceholder('source'))
656
- await userEvent.cut()
657
-
658
- // paste to 'target'
659
- await userEvent.click(page.getByPlaceholder('target'))
660
- await userEvent.paste()
661
-
662
- await expect.element(page.getByPlaceholder('source')).toHaveTextContent('')
663
- await expect.element(page.getByPlaceholder('target')).toHaveTextContent('hello')
664
- })
665
- ```
666
-
667
- References:
668
-
669
- - [testing-library `cut` API](https://testing-library.com/docs/user-event/clipboard#cut)
670
-
671
- ## userEvent.paste
672
-
673
- ```ts
674
- function paste(): Promise<void>
675
- ```
676
-
677
- Paste the text from the clipboard. See [`userEvent.copy`](#userevent-copy) and [`userEvent.cut`](#userevent-cut) for usage examples.
678
-
679
- References:
680
-
681
- - [testing-library `paste` API](https://testing-library.com/docs/user-event/clipboard#paste)