@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,222 +0,0 @@
1
- # vitest-browser-vue
2
-
3
- The community [`vitest-browser-vue`](https://npmx.dev/package/vitest-browser-vue) package renders [Vue](https://vuejs.org/) components in [Browser Mode](/guide/browser/).
4
-
5
- ```ts
6
- import { render } from 'vitest-browser-vue'
7
- import { expect, test } from 'vitest'
8
- import Component from './Component.vue'
9
-
10
- test('counter button increments the count', async () => {
11
- const screen = await render(Component, {
12
- props: {
13
- initialCount: 1,
14
- }
15
- })
16
-
17
- await screen.getByRole('button', { name: 'Increment' }).click()
18
-
19
- await expect.element(screen.getByText('Count is 2')).toBeVisible()
20
- })
21
- ```
22
-
23
- ::: warning
24
- This library takes inspiration from [`@testing-library/vue`](https://github.com/testing-library/vue-testing-library).
25
-
26
- If you have used `@testing-library/vue` in your tests before, you can keep using it, however the `vitest-browser-vue` package provides certain benefits unique to the Browser Mode that `@testing-library/vue` lacks:
27
-
28
- `vitest-browser-vue` returns APIs that interact well with built-in [locators](/api/browser/locators), [user events](/api/browser/interactivity) and [assertions](/api/browser/assertions): for example, Vitest will automatically retry the element until the assertion is successful, even if it was rerendered between the assertions.
29
- :::
30
-
31
- The package exposes two entry points: `vitest-browser-vue` and `vitest-browser-vue/pure`. They expose identical API, but the `pure` entry point doesn't add a handler to remove the component before the next test has started.
32
-
33
- ## render
34
-
35
- ```ts
36
- export function render(
37
- component: Component,
38
- options?: ComponentRenderOptions,
39
- ): RenderResult & PromiseLike<RenderResult>
40
- ```
41
-
42
- The `render` function records a `vue.render` trace mark, visible in the [Trace View](/guide/browser/trace-view).
43
-
44
- ::: warning
45
- Synchronous usage of `render` is deprecated and will be removed in the next major version. Please always `await` the result:
46
-
47
- ```ts
48
- const screen = render(Component) // [!code --]
49
- const screen = await render(Component) // [!code ++]
50
- ```
51
- :::
52
-
53
- ### Options
54
-
55
- The `render` function supports all [`mount` options](https://test-utils.vuejs.org/api/#mount) from `@vue/test-utils` (except `attachTo` - use `container` instead). In addition to them, there are also `container` and `baseElement`.
56
-
57
- #### container
58
-
59
- By default, Vitest will create a `div`, append it to `document.body`, and render your component there. If you provide your own `HTMLElement` container, it will not be appended automatically — you'll need to call `document.body.appendChild(container)` before `render`.
60
-
61
- For example, if you are unit testing a `tbody` element, it cannot be a child of a `div`. In this case, you can specify a `table` as the render container.
62
-
63
- ```js
64
- const table = document.createElement('table')
65
-
66
- const { container } = await render(TableBody, {
67
- props,
68
- // ⚠️ appending the element to `body` manually before rendering
69
- container: document.body.appendChild(table),
70
- })
71
- ```
72
-
73
- #### baseElement
74
-
75
- If the `container` is specified, then this defaults to that, otherwise this defaults to `document.body`. This is used as the base element for the queries as well as what is printed when you use `debug()`.
76
-
77
- ### Render Result
78
-
79
- In addition to documented return value, the `render` function also returns all available [locators](/api/browser/locators) relative to the [`baseElement`](#baseelement), including [custom ones](/api/browser/locators#custom-locators).
80
-
81
- ```ts
82
- const screen = await render(TableBody, { props })
83
-
84
- await screen.getByRole('link', { name: 'Expand' }).click()
85
- ```
86
-
87
- #### container
88
-
89
- The containing DOM node where your Vue component is rendered. This is a regular DOM node, so you technically could call `container.querySelector` etc. to inspect the children.
90
-
91
- :::danger
92
- If you find yourself using `container` to query for rendered elements then you should reconsider! The [locators](/api/browser/locators) are designed to be more resilient to changes that will be made to the component you're testing. Avoid using `container` to query for elements!
93
- :::
94
-
95
- #### baseElement
96
-
97
- The containing DOM node where your Vue component is rendered in the `container`. If you don't specify the `baseElement` in the options of render, it will default to `document.body`.
98
-
99
- This is useful when the component you want to test renders something outside the container `div`, e.g. when you want to snapshot test your portal component which renders its HTML directly in the body.
100
-
101
- :::tip
102
- The queries returned by the `render` looks into `baseElement`, so you can use queries to test your portal component without the `baseElement`.
103
- :::
104
-
105
- #### locator
106
-
107
- The [locator](/api/browser/locators) of your `container`. It is useful to use queries scoped only to your component, or pass it down to other assertions:
108
-
109
- ```js
110
- import { render } from 'vitest-browser-vue'
111
-
112
- const { locator } = await render(NumberDisplay, {
113
- props: { number: 2 }
114
- })
115
-
116
- await locator.getByRole('button').click()
117
- await expect.element(locator).toHaveTextContent('Hello World')
118
- ```
119
-
120
- #### debug
121
-
122
- ```ts
123
- function debug(
124
- el?: HTMLElement | HTMLElement[] | Locator | Locator[],
125
- maxLength?: number,
126
- options?: PrettyDOMOptions,
127
- ): void
128
- ```
129
-
130
- This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will print the DOM content of the container or specified elements to the console.
131
-
132
- #### rerender
133
-
134
- ```ts
135
- function rerender(props: Partial<Props>): void & PromiseLike<void>
136
- ```
137
-
138
- Also records a `vue.rerender` trace mark in the [Trace View](/guide/browser/trace-view).
139
-
140
- It is better if you test the component that's doing the prop updating to ensure that the props are being updated correctly to avoid relying on implementation details in your tests. That said, if you'd prefer to update the props of a rendered component in your test, this function can be used to update props of the rendered component.
141
-
142
- ::: warning
143
- Synchronous usage of `rerender` is deprecated and will be removed in the next major version. Please always `await` the result.
144
- :::
145
-
146
- ```js
147
- import { render } from 'vitest-browser-vue'
148
-
149
- const { rerender } = await render(NumberDisplay, { props: { number: 1 } })
150
-
151
- // re-render the same component with different props
152
- await rerender({ number: 2 })
153
- ```
154
-
155
- #### unmount
156
-
157
- ```ts
158
- function unmount(): void & PromiseLike<void>
159
- ```
160
-
161
- This will cause the rendered component to be unmounted. Also records a `vue.unmount` trace mark in the [Trace View](/guide/browser/trace-view). This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks).
162
-
163
- ::: warning
164
- Synchronous usage of `unmount` is deprecated and will be removed in the next major version. Please always `await` the result.
165
- :::
166
-
167
- #### emitted
168
-
169
- ```ts
170
- function emitted<T = unknown>(): Record<string, T[]>
171
- function emitted<T = unknown[]>(eventName: string): undefined | T[]
172
- ```
173
-
174
- Returns the emitted events from the Component.
175
-
176
- ::: warning
177
- Emitted values are an implementation detail not exposed directly to the user, so it is better to test how your emitted values are changing the displayed content by using [locators](/api/browser/locators) instead.
178
- :::
179
-
180
- ## cleanup
181
-
182
- ```ts
183
- export function cleanup(): void
184
- ```
185
-
186
- Remove all components rendered with [`render`](#render).
187
-
188
- ## Extend Queries
189
-
190
- To extend locator queries, see [`"Custom Locators"`](/api/browser/locators#custom-locators). For example, to make `render` return a new custom locator, define it using the `locators.extend` API:
191
-
192
- ```js {5-7,12}
193
- import { locators } from 'vitest/browser'
194
- import { render } from 'vitest-browser-vue'
195
-
196
- locators.extend({
197
- getByArticleTitle(title) {
198
- return `[data-title="${title}"]`
199
- },
200
- })
201
-
202
- const screen = await render(Component)
203
- await expect.element(
204
- screen.getByArticleTitle('Hello World')
205
- ).toBeVisible()
206
- ```
207
-
208
- ## Configuration
209
-
210
- You can configure [Vue Test Utils](https://test-utils.vuejs.org/api/#config) options by assigning properties to the `config` export (available in both `vitest-browser-vue` and `vitest-browser-vue/pure`):
211
-
212
- ```js
213
- import { config } from 'vitest-browser-vue/pure'
214
-
215
- config.global.stubs.CustomComponent = {
216
- template: '<div></div>',
217
- }
218
- ```
219
-
220
- ## See also
221
-
222
- - [Vue Testing Library documentation](https://testing-library.com/docs/vue-testing-library/intro)
@@ -1,374 +0,0 @@
1
- # describe
2
-
3
- - **Alias:** `suite`
4
-
5
- ```ts
6
- function describe(
7
- name: string | Function,
8
- body?: () => unknown,
9
- timeout?: number
10
- ): void
11
- function describe(
12
- name: string | Function,
13
- options: SuiteOptions,
14
- body?: () => unknown,
15
- ): void
16
- ```
17
-
18
- `describe` is used to group related tests and benchmarks into a suite. Suites help organize your test files by creating logical blocks, making test output easier to read and enabling shared setup/teardown through [lifecycle hooks](/api/hooks).
19
-
20
- When you use `test` in the top level of file, they are collected as part of the implicit suite for it. Using `describe` you can define a new suite in the current context, as a set of related tests or benchmarks and other nested suites.
21
-
22
- ```ts [basic.spec.ts]
23
- import { describe, expect, test } from 'vitest'
24
-
25
- const person = {
26
- isActive: true,
27
- age: 32,
28
- }
29
-
30
- describe('person', () => {
31
- test('person is defined', () => {
32
- expect(person).toBeDefined()
33
- })
34
-
35
- test('is active', () => {
36
- expect(person.isActive).toBeTruthy()
37
- })
38
-
39
- test('age limit', () => {
40
- expect(person.age).toBeLessThanOrEqual(32)
41
- })
42
- })
43
- ```
44
-
45
- You can also nest `describe` blocks if you have a hierarchy of tests:
46
-
47
- ```ts
48
- import { describe, expect, test } from 'vitest'
49
-
50
- function numberToCurrency(value: number | string) {
51
- if (typeof value !== 'number') {
52
- throw new TypeError('Value must be a number')
53
- }
54
-
55
- return value.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
56
- }
57
-
58
- describe('numberToCurrency', () => {
59
- describe('given an invalid number', () => {
60
- test('composed of non-numbers to throw error', () => {
61
- expect(() => numberToCurrency('abc')).toThrow()
62
- })
63
- })
64
-
65
- describe('given a valid number', () => {
66
- test('returns the correct currency format', () => {
67
- expect(numberToCurrency(10000)).toBe('10,000.00')
68
- })
69
- })
70
- })
71
- ```
72
-
73
- ## Test Options
74
-
75
- You can use [test options](/api/test#test-options) to apply configuration to every test inside a suite, including nested suites. This is useful when you want to set timeouts, retries, or other options for a group of related tests.
76
-
77
- ```ts
78
- import { describe, test } from 'vitest'
79
-
80
- describe('slow tests', { timeout: 10_000 }, () => {
81
- test('test 1', () => { /* ... */ })
82
- test('test 2', () => { /* ... */ })
83
-
84
- // nested suites also inherit the timeout
85
- describe('nested', () => {
86
- test('test 3', () => { /* ... */ })
87
- })
88
- })
89
- ```
90
-
91
- ### `shuffle`
92
-
93
- - **Type:** `boolean`
94
- - **Default:** `false` (configured by [`sequence.shuffle`](/config/sequence#sequence-shuffle))
95
- - **Alias:** [`describe.shuffle`](#describe-shuffle)
96
-
97
- Run tests within the suite in random order. This option is inherited by nested suites.
98
-
99
- ```ts
100
- import { describe, test } from 'vitest'
101
-
102
- describe('randomized tests', { shuffle: true }, () => {
103
- test('test 1', () => { /* ... */ })
104
- test('test 2', () => { /* ... */ })
105
- test('test 3', () => { /* ... */ })
106
- })
107
- ```
108
-
109
- ## describe.skip
110
-
111
- - **Alias:** `suite.skip`
112
-
113
- Use `describe.skip` in a suite to avoid running a particular describe block.
114
-
115
- ```ts
116
- import { assert, describe, test } from 'vitest'
117
-
118
- describe.skip('skipped suite', () => {
119
- test('sqrt', () => {
120
- // Suite skipped, no error
121
- assert.equal(Math.sqrt(4), 3)
122
- })
123
- })
124
- ```
125
-
126
- ## describe.skipIf
127
-
128
- - **Alias:** `suite.skipIf`
129
-
130
- In some cases, you might run suites multiple times with different environments, and some of the suites might be environment-specific. Instead of wrapping the suite with `if`, you can use `describe.skipIf` to skip the suite whenever the condition is truthy.
131
-
132
- ```ts
133
- import { describe, test } from 'vitest'
134
-
135
- const isDev = process.env.NODE_ENV === 'development'
136
-
137
- describe.skipIf(isDev)('prod only test suite', () => {
138
- // this test suite only runs in production
139
- })
140
- ```
141
-
142
- ## describe.runIf
143
-
144
- - **Alias:** `suite.runIf`
145
-
146
- Opposite of [describe.skipIf](#describe-skipif).
147
-
148
- ```ts
149
- import { assert, describe, test } from 'vitest'
150
-
151
- const isDev = process.env.NODE_ENV === 'development'
152
-
153
- describe.runIf(isDev)('dev only test suite', () => {
154
- // this test suite only runs in development
155
- })
156
- ```
157
-
158
- ## describe.only
159
-
160
- - **Alias:** `suite.only`
161
-
162
- Use `describe.only` to only run certain suites
163
-
164
- ```ts
165
- import { assert, describe, test } from 'vitest'
166
-
167
- // Only this suite (and others marked with only) are run
168
- describe.only('suite', () => {
169
- test('sqrt', () => {
170
- assert.equal(Math.sqrt(4), 3)
171
- })
172
- })
173
-
174
- describe('other suite', () => {
175
- // ... will be skipped
176
- })
177
- ```
178
-
179
- Sometimes it is very useful to run `only` tests in a certain file, ignoring all other tests from the whole test suite, which pollute the output.
180
-
181
- In order to do that, run `vitest` with specific file containing the tests in question:
182
-
183
- ```shell
184
- vitest interesting.test.ts
185
- ```
186
-
187
- ## describe.concurrent
188
-
189
- - **Alias:** `suite.concurrent`
190
-
191
- `describe.concurrent` runs all inner suites and tests in parallel
192
-
193
- ```ts
194
- import { describe, test } from 'vitest'
195
-
196
- // All suites and tests within this suite will be run in parallel
197
- describe.concurrent('suite', () => {
198
- test('concurrent test 1', async () => { /* ... */ })
199
- describe('concurrent suite 2', async () => {
200
- test('concurrent test inner 1', async () => { /* ... */ })
201
- test('concurrent test inner 2', async () => { /* ... */ })
202
- })
203
- test.concurrent('concurrent test 3', async () => { /* ... */ })
204
- })
205
- ```
206
-
207
- `.skip`, `.only`, and `.todo` works with concurrent suites. All the following combinations are valid:
208
-
209
- ```ts
210
- describe.concurrent(/* ... */)
211
- describe.skip.concurrent(/* ... */) // or describe.concurrent.skip(/* ... */)
212
- describe.only.concurrent(/* ... */) // or describe.concurrent.only(/* ... */)
213
- describe.todo.concurrent(/* ... */) // or describe.concurrent.todo(/* ... */)
214
- ```
215
-
216
- When running concurrent tests, Snapshots and Assertions must use `expect` from the local [Test Context](/guide/test-context) to ensure the right test is detected.
217
-
218
- ```ts
219
- describe.concurrent('suite', () => {
220
- test('concurrent test 1', async ({ expect }) => {
221
- expect(foo).toMatchSnapshot()
222
- })
223
- test('concurrent test 2', async ({ expect }) => {
224
- expect(foo).toMatchSnapshot()
225
- })
226
- })
227
- ```
228
-
229
- ## describe.sequential
230
-
231
- - **Alias:** `suite.sequential`
232
-
233
- `describe.sequential` in a suite marks every test as sequential. This is useful if you want to run tests in sequence within `describe.concurrent` or with the `--sequence.concurrent` command option.
234
-
235
- ```ts
236
- import { describe, test } from 'vitest'
237
-
238
- describe.concurrent('suite', () => {
239
- test('concurrent test 1', async () => { /* ... */ })
240
- test('concurrent test 2', async () => { /* ... */ })
241
-
242
- describe.sequential('', () => {
243
- test('sequential test 1', async () => { /* ... */ })
244
- test('sequential test 2', async () => { /* ... */ })
245
- })
246
- })
247
- ```
248
-
249
- ## describe.shuffle
250
-
251
- - **Alias:** `suite.shuffle`
252
-
253
- Vitest provides a way to run all tests in random order via CLI flag [`--sequence.shuffle`](/guide/cli) or config option [`sequence.shuffle`](/config/sequence#sequence-shuffle), but if you want to have only part of your test suite to run tests in random order, you can mark it with this flag.
254
-
255
- ```ts
256
- import { describe, test } from 'vitest'
257
-
258
- // or describe('suite', { shuffle: true }, ...)
259
- describe.shuffle('suite', () => {
260
- test('random test 1', async () => { /* ... */ })
261
- test('random test 2', async () => { /* ... */ })
262
- test('random test 3', async () => { /* ... */ })
263
-
264
- // `shuffle` is inherited
265
- describe('still random', () => {
266
- test('random 4.1', async () => { /* ... */ })
267
- test('random 4.2', async () => { /* ... */ })
268
- })
269
-
270
- // disable shuffle inside
271
- describe('not random', { shuffle: false }, () => {
272
- test('in order 5.1', async () => { /* ... */ })
273
- test('in order 5.2', async () => { /* ... */ })
274
- })
275
- })
276
- // order depends on sequence.seed option in config (Date.now() by default)
277
- ```
278
-
279
- `.skip`, `.only`, and `.todo` works with random suites.
280
-
281
- ## describe.todo
282
-
283
- - **Alias:** `suite.todo`
284
-
285
- Use `describe.todo` to stub suites to be implemented later. An entry will be shown in the report for the tests so you know how many tests you still need to implement.
286
-
287
- ```ts
288
- // An entry will be shown in the report for this suite
289
- describe.todo('unimplemented suite')
290
- ```
291
-
292
- ## describe.each
293
-
294
- - **Alias:** `suite.each`
295
-
296
- ::: tip
297
- While `describe.each` is provided for Jest compatibility,
298
- Vitest also has [`describe.for`](#describe-for) which simplifies argument types and aligns with [`test.for`](/api/test#test-for).
299
- :::
300
-
301
- Use `describe.each` if you have more than one test that depends on the same data.
302
-
303
- ```ts
304
- import { describe, expect, test } from 'vitest'
305
-
306
- describe.each([
307
- { a: 1, b: 1, expected: 2 },
308
- { a: 1, b: 2, expected: 3 },
309
- { a: 2, b: 1, expected: 3 },
310
- ])('describe object add($a, $b)', ({ a, b, expected }) => {
311
- test(`returns ${expected}`, () => {
312
- expect(a + b).toBe(expected)
313
- })
314
-
315
- test(`returned value not be greater than ${expected}`, () => {
316
- expect(a + b).not.toBeGreaterThan(expected)
317
- })
318
-
319
- test(`returned value not be less than ${expected}`, () => {
320
- expect(a + b).not.toBeLessThan(expected)
321
- })
322
- })
323
- ```
324
-
325
- * First row should be column names, separated by `|`;
326
- * One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
327
-
328
- ```ts
329
- import { describe, expect, test } from 'vitest'
330
-
331
- describe.each`
332
- a | b | expected
333
- ${1} | ${1} | ${2}
334
- ${'a'} | ${'b'} | ${'ab'}
335
- ${[]} | ${'b'} | ${'b'}
336
- ${{}} | ${'b'} | ${'[object Object]b'}
337
- ${{ asd: 1 }} | ${'b'} | ${'[object Object]b'}
338
- `('describe template string add($a, $b)', ({ a, b, expected }) => {
339
- test(`returns ${expected}`, () => {
340
- expect(a + b).toBe(expected)
341
- })
342
- })
343
- ```
344
-
345
- ## describe.for
346
-
347
- - **Alias:** `suite.for`
348
-
349
- The difference from `describe.each` is how array case is provided in the arguments.
350
- Other non array case (including template string usage) works exactly same.
351
-
352
- ```ts
353
- // `each` spreads array case
354
- describe.each([
355
- [1, 1, 2],
356
- [1, 2, 3],
357
- [2, 1, 3],
358
- ])('add(%i, %i) -> %i', (a, b, expected) => { // [!code --]
359
- test('test', () => {
360
- expect(a + b).toBe(expected)
361
- })
362
- })
363
-
364
- // `for` doesn't spread array case
365
- describe.for([
366
- [1, 1, 2],
367
- [1, 2, 3],
368
- [2, 1, 3],
369
- ])('add(%i, %i) -> %i', ([a, b, expected]) => { // [!code ++]
370
- test('test', () => {
371
- expect(a + b).toBe(expected)
372
- })
373
- })
374
- ```