@vitest-agent/mcp 1.1.0 → 1.3.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 (209) hide show
  1. package/README.md +1 -2
  2. package/index.d.ts +3 -2
  3. package/index.js +1 -1
  4. package/package.json +1 -1
  5. package/server.js +2 -4
  6. package/tools/run-tests.js +17 -3
  7. package/patterns/_meta.json +0 -67
  8. package/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
  9. package/patterns/known-issues-and-caveats.md +0 -52
  10. package/patterns/operating-vitest-agent-as-an-agent.md +0 -62
  11. package/patterns/running-tests-via-mcp.md +0 -103
  12. package/patterns/silencing-leaking-output-in-tests.md +0 -91
  13. package/patterns/testing-effect-schema-definitions.md +0 -71
  14. package/patterns/testing-effect-services-with-mock-layers.md +0 -63
  15. package/resources/index.js +0 -166
  16. package/resources/indexes.js +0 -77
  17. package/resources/manifest-schema.js +0 -46
  18. package/resources/paths.js +0 -20
  19. package/resources/patterns.js +0 -22
  20. package/resources/upstream-docs.js +0 -22
  21. package/vendor/vitest-docs/ATTRIBUTION.md +0 -5
  22. package/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
  23. package/vendor/vitest-docs/api/advanced/metadata.md +0 -68
  24. package/vendor/vitest-docs/api/advanced/plugin.md +0 -168
  25. package/vendor/vitest-docs/api/advanced/reporters.md +0 -342
  26. package/vendor/vitest-docs/api/advanced/runner.md +0 -334
  27. package/vendor/vitest-docs/api/advanced/test-case.md +0 -302
  28. package/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
  29. package/vendor/vitest-docs/api/advanced/test-module.md +0 -140
  30. package/vendor/vitest-docs/api/advanced/test-project.md +0 -321
  31. package/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
  32. package/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
  33. package/vendor/vitest-docs/api/advanced/vitest.md +0 -684
  34. package/vendor/vitest-docs/api/assert-type.md +0 -22
  35. package/vendor/vitest-docs/api/assert.md +0 -1960
  36. package/vendor/vitest-docs/api/browser/assertions.md +0 -1277
  37. package/vendor/vitest-docs/api/browser/commands.md +0 -154
  38. package/vendor/vitest-docs/api/browser/context.md +0 -338
  39. package/vendor/vitest-docs/api/browser/interactivity.md +0 -681
  40. package/vendor/vitest-docs/api/browser/locators.md +0 -1171
  41. package/vendor/vitest-docs/api/browser/react.md +0 -346
  42. package/vendor/vitest-docs/api/browser/svelte.md +0 -292
  43. package/vendor/vitest-docs/api/browser/vue.md +0 -222
  44. package/vendor/vitest-docs/api/describe.md +0 -374
  45. package/vendor/vitest-docs/api/expect-typeof.md +0 -571
  46. package/vendor/vitest-docs/api/expect.md +0 -2304
  47. package/vendor/vitest-docs/api/hooks.md +0 -463
  48. package/vendor/vitest-docs/api/mock.md +0 -701
  49. package/vendor/vitest-docs/api/test.md +0 -926
  50. package/vendor/vitest-docs/api/vi.md +0 -1372
  51. package/vendor/vitest-docs/config/alias.md +0 -13
  52. package/vendor/vitest-docs/config/allowonly.md +0 -32
  53. package/vendor/vitest-docs/config/api.md +0 -27
  54. package/vendor/vitest-docs/config/attachmentsdir.md +0 -6
  55. package/vendor/vitest-docs/config/bail.md +0 -9
  56. package/vendor/vitest-docs/config/benchmark.md +0 -65
  57. package/vendor/vitest-docs/config/browser/api.md +0 -23
  58. package/vendor/vitest-docs/config/browser/commands.md +0 -6
  59. package/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
  60. package/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
  61. package/vendor/vitest-docs/config/browser/enabled.md +0 -40
  62. package/vendor/vitest-docs/config/browser/expect.md +0 -250
  63. package/vendor/vitest-docs/config/browser/headless.md +0 -7
  64. package/vendor/vitest-docs/config/browser/instances.md +0 -47
  65. package/vendor/vitest-docs/config/browser/isolate.md +0 -11
  66. package/vendor/vitest-docs/config/browser/locators.md +0 -24
  67. package/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
  68. package/vendor/vitest-docs/config/browser/playwright.md +0 -214
  69. package/vendor/vitest-docs/config/browser/preview.md +0 -32
  70. package/vendor/vitest-docs/config/browser/provider.md +0 -79
  71. package/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
  72. package/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
  73. package/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
  74. package/vendor/vitest-docs/config/browser/trace.md +0 -43
  75. package/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
  76. package/vendor/vitest-docs/config/browser/ui.md +0 -7
  77. package/vendor/vitest-docs/config/browser/viewport.md +0 -6
  78. package/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
  79. package/vendor/vitest-docs/config/cache.md +0 -26
  80. package/vendor/vitest-docs/config/chaiconfig.md +0 -29
  81. package/vendor/vitest-docs/config/clearmocks.md +0 -22
  82. package/vendor/vitest-docs/config/coverage.md +0 -455
  83. package/vendor/vitest-docs/config/css.md +0 -47
  84. package/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
  85. package/vendor/vitest-docs/config/deps.md +0 -127
  86. package/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
  87. package/vendor/vitest-docs/config/diff.md +0 -96
  88. package/vendor/vitest-docs/config/dir.md +0 -7
  89. package/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
  90. package/vendor/vitest-docs/config/env.md +0 -5
  91. package/vendor/vitest-docs/config/environment.md +0 -96
  92. package/vendor/vitest-docs/config/environmentoptions.md +0 -30
  93. package/vendor/vitest-docs/config/exclude.md +0 -49
  94. package/vendor/vitest-docs/config/execargv.md +0 -10
  95. package/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
  96. package/vendor/vitest-docs/config/expect.md +0 -38
  97. package/vendor/vitest-docs/config/experimental.md +0 -510
  98. package/vendor/vitest-docs/config/faketimers.md +0 -51
  99. package/vendor/vitest-docs/config/fileparallelism.md +0 -11
  100. package/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
  101. package/vendor/vitest-docs/config/globals.md +0 -42
  102. package/vendor/vitest-docs/config/globalsetup.md +0 -72
  103. package/vendor/vitest-docs/config/hideskippedtests.md +0 -7
  104. package/vendor/vitest-docs/config/hooktimeout.md +0 -7
  105. package/vendor/vitest-docs/config/include-source.md +0 -115
  106. package/vendor/vitest-docs/config/include.md +0 -71
  107. package/vendor/vitest-docs/config/includetasklocation.md +0 -17
  108. package/vendor/vitest-docs/config/index.md +0 -85
  109. package/vendor/vitest-docs/config/isolate.md +0 -13
  110. package/vendor/vitest-docs/config/logheapusage.md +0 -7
  111. package/vendor/vitest-docs/config/maxconcurrency.md +0 -9
  112. package/vendor/vitest-docs/config/maxworkers.md +0 -49
  113. package/vendor/vitest-docs/config/mockreset.md +0 -22
  114. package/vendor/vitest-docs/config/mode.md +0 -7
  115. package/vendor/vitest-docs/config/name.md +0 -111
  116. package/vendor/vitest-docs/config/onconsolelog.md +0 -25
  117. package/vendor/vitest-docs/config/onstacktrace.md +0 -32
  118. package/vendor/vitest-docs/config/onunhandlederror.md +0 -35
  119. package/vendor/vitest-docs/config/open.md +0 -7
  120. package/vendor/vitest-docs/config/outputfile.md +0 -7
  121. package/vendor/vitest-docs/config/passwithnotests.md +0 -7
  122. package/vendor/vitest-docs/config/pool.md +0 -45
  123. package/vendor/vitest-docs/config/printconsoletrace.md +0 -6
  124. package/vendor/vitest-docs/config/projects.md +0 -6
  125. package/vendor/vitest-docs/config/provide.md +0 -45
  126. package/vendor/vitest-docs/config/reporters.md +0 -69
  127. package/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
  128. package/vendor/vitest-docs/config/restoremocks.md +0 -22
  129. package/vendor/vitest-docs/config/retry.md +0 -140
  130. package/vendor/vitest-docs/config/root.md +0 -6
  131. package/vendor/vitest-docs/config/runner.md +0 -6
  132. package/vendor/vitest-docs/config/sequence.md +0 -158
  133. package/vendor/vitest-docs/config/server.md +0 -68
  134. package/vendor/vitest-docs/config/setupfiles.md +0 -40
  135. package/vendor/vitest-docs/config/silent.md +0 -9
  136. package/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
  137. package/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
  138. package/vendor/vitest-docs/config/snapshotformat.md +0 -28
  139. package/vendor/vitest-docs/config/snapshotserializers.md +0 -6
  140. package/vendor/vitest-docs/config/stricttags.md +0 -30
  141. package/vendor/vitest-docs/config/tags.md +0 -141
  142. package/vendor/vitest-docs/config/teardowntimeout.md +0 -7
  143. package/vendor/vitest-docs/config/testnamepattern.md +0 -21
  144. package/vendor/vitest-docs/config/testtimeout.md +0 -7
  145. package/vendor/vitest-docs/config/typecheck.md +0 -77
  146. package/vendor/vitest-docs/config/ui.md +0 -15
  147. package/vendor/vitest-docs/config/unstubenvs.md +0 -20
  148. package/vendor/vitest-docs/config/unstubglobals.md +0 -20
  149. package/vendor/vitest-docs/config/update.md +0 -16
  150. package/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
  151. package/vendor/vitest-docs/config/watch.md +0 -11
  152. package/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
  153. package/vendor/vitest-docs/guide/advanced/index.md +0 -147
  154. package/vendor/vitest-docs/guide/advanced/pool.md +0 -148
  155. package/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
  156. package/vendor/vitest-docs/guide/advanced/tests.md +0 -125
  157. package/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
  158. package/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
  159. package/vendor/vitest-docs/guide/browser/index.md +0 -630
  160. package/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
  161. package/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
  162. package/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
  163. package/vendor/vitest-docs/guide/cli-generated.md +0 -972
  164. package/vendor/vitest-docs/guide/cli.md +0 -234
  165. package/vendor/vitest-docs/guide/common-errors.md +0 -163
  166. package/vendor/vitest-docs/guide/coverage.md +0 -515
  167. package/vendor/vitest-docs/guide/debugging.md +0 -127
  168. package/vendor/vitest-docs/guide/environment.md +0 -101
  169. package/vendor/vitest-docs/guide/extending-matchers.md +0 -160
  170. package/vendor/vitest-docs/guide/features.md +0 -310
  171. package/vendor/vitest-docs/guide/filtering.md +0 -175
  172. package/vendor/vitest-docs/guide/ide.md +0 -43
  173. package/vendor/vitest-docs/guide/improving-performance.md +0 -245
  174. package/vendor/vitest-docs/guide/in-source.md +0 -159
  175. package/vendor/vitest-docs/guide/index.md +0 -128
  176. package/vendor/vitest-docs/guide/learn/async.md +0 -147
  177. package/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
  178. package/vendor/vitest-docs/guide/learn/matchers.md +0 -277
  179. package/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
  180. package/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
  181. package/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
  182. package/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
  183. package/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
  184. package/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
  185. package/vendor/vitest-docs/guide/lifecycle.md +0 -379
  186. package/vendor/vitest-docs/guide/migration.md +0 -863
  187. package/vendor/vitest-docs/guide/mocking/classes.md +0 -158
  188. package/vendor/vitest-docs/guide/mocking/dates.md +0 -52
  189. package/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
  190. package/vendor/vitest-docs/guide/mocking/functions.md +0 -61
  191. package/vendor/vitest-docs/guide/mocking/globals.md +0 -20
  192. package/vendor/vitest-docs/guide/mocking/modules.md +0 -414
  193. package/vendor/vitest-docs/guide/mocking/requests.md +0 -114
  194. package/vendor/vitest-docs/guide/mocking/timers.md +0 -48
  195. package/vendor/vitest-docs/guide/mocking.md +0 -239
  196. package/vendor/vitest-docs/guide/open-telemetry.md +0 -156
  197. package/vendor/vitest-docs/guide/parallelism.md +0 -82
  198. package/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
  199. package/vendor/vitest-docs/guide/projects.md +0 -291
  200. package/vendor/vitest-docs/guide/recipes.md +0 -59
  201. package/vendor/vitest-docs/guide/reporters.md +0 -723
  202. package/vendor/vitest-docs/guide/snapshot.md +0 -620
  203. package/vendor/vitest-docs/guide/test-annotations.md +0 -103
  204. package/vendor/vitest-docs/guide/test-context.md +0 -902
  205. package/vendor/vitest-docs/guide/test-tags.md +0 -314
  206. package/vendor/vitest-docs/guide/testing-types.md +0 -149
  207. package/vendor/vitest-docs/guide/ui.md +0 -160
  208. package/vendor/vitest-docs/guide/using-plugins.md +0 -5
  209. package/vendor/vitest-docs/manifest.json +0 -1691
@@ -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
- ```