@vitest-agent/mcp 1.1.0 → 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 (208) hide show
  1. package/README.md +1 -2
  2. package/index.d.ts +2 -2
  3. package/index.js +1 -1
  4. package/package.json +1 -1
  5. package/server.js +2 -4
  6. package/patterns/_meta.json +0 -67
  7. package/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
  8. package/patterns/known-issues-and-caveats.md +0 -52
  9. package/patterns/operating-vitest-agent-as-an-agent.md +0 -62
  10. package/patterns/running-tests-via-mcp.md +0 -103
  11. package/patterns/silencing-leaking-output-in-tests.md +0 -91
  12. package/patterns/testing-effect-schema-definitions.md +0 -71
  13. package/patterns/testing-effect-services-with-mock-layers.md +0 -63
  14. package/resources/index.js +0 -166
  15. package/resources/indexes.js +0 -77
  16. package/resources/manifest-schema.js +0 -46
  17. package/resources/paths.js +0 -20
  18. package/resources/patterns.js +0 -22
  19. package/resources/upstream-docs.js +0 -22
  20. package/vendor/vitest-docs/ATTRIBUTION.md +0 -5
  21. package/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
  22. package/vendor/vitest-docs/api/advanced/metadata.md +0 -68
  23. package/vendor/vitest-docs/api/advanced/plugin.md +0 -168
  24. package/vendor/vitest-docs/api/advanced/reporters.md +0 -342
  25. package/vendor/vitest-docs/api/advanced/runner.md +0 -334
  26. package/vendor/vitest-docs/api/advanced/test-case.md +0 -302
  27. package/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
  28. package/vendor/vitest-docs/api/advanced/test-module.md +0 -140
  29. package/vendor/vitest-docs/api/advanced/test-project.md +0 -321
  30. package/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
  31. package/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
  32. package/vendor/vitest-docs/api/advanced/vitest.md +0 -684
  33. package/vendor/vitest-docs/api/assert-type.md +0 -22
  34. package/vendor/vitest-docs/api/assert.md +0 -1960
  35. package/vendor/vitest-docs/api/browser/assertions.md +0 -1277
  36. package/vendor/vitest-docs/api/browser/commands.md +0 -154
  37. package/vendor/vitest-docs/api/browser/context.md +0 -338
  38. package/vendor/vitest-docs/api/browser/interactivity.md +0 -681
  39. package/vendor/vitest-docs/api/browser/locators.md +0 -1171
  40. package/vendor/vitest-docs/api/browser/react.md +0 -346
  41. package/vendor/vitest-docs/api/browser/svelte.md +0 -292
  42. package/vendor/vitest-docs/api/browser/vue.md +0 -222
  43. package/vendor/vitest-docs/api/describe.md +0 -374
  44. package/vendor/vitest-docs/api/expect-typeof.md +0 -571
  45. package/vendor/vitest-docs/api/expect.md +0 -2304
  46. package/vendor/vitest-docs/api/hooks.md +0 -463
  47. package/vendor/vitest-docs/api/mock.md +0 -701
  48. package/vendor/vitest-docs/api/test.md +0 -926
  49. package/vendor/vitest-docs/api/vi.md +0 -1372
  50. package/vendor/vitest-docs/config/alias.md +0 -13
  51. package/vendor/vitest-docs/config/allowonly.md +0 -32
  52. package/vendor/vitest-docs/config/api.md +0 -27
  53. package/vendor/vitest-docs/config/attachmentsdir.md +0 -6
  54. package/vendor/vitest-docs/config/bail.md +0 -9
  55. package/vendor/vitest-docs/config/benchmark.md +0 -65
  56. package/vendor/vitest-docs/config/browser/api.md +0 -23
  57. package/vendor/vitest-docs/config/browser/commands.md +0 -6
  58. package/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
  59. package/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
  60. package/vendor/vitest-docs/config/browser/enabled.md +0 -40
  61. package/vendor/vitest-docs/config/browser/expect.md +0 -250
  62. package/vendor/vitest-docs/config/browser/headless.md +0 -7
  63. package/vendor/vitest-docs/config/browser/instances.md +0 -47
  64. package/vendor/vitest-docs/config/browser/isolate.md +0 -11
  65. package/vendor/vitest-docs/config/browser/locators.md +0 -24
  66. package/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
  67. package/vendor/vitest-docs/config/browser/playwright.md +0 -214
  68. package/vendor/vitest-docs/config/browser/preview.md +0 -32
  69. package/vendor/vitest-docs/config/browser/provider.md +0 -79
  70. package/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
  71. package/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
  72. package/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
  73. package/vendor/vitest-docs/config/browser/trace.md +0 -43
  74. package/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
  75. package/vendor/vitest-docs/config/browser/ui.md +0 -7
  76. package/vendor/vitest-docs/config/browser/viewport.md +0 -6
  77. package/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
  78. package/vendor/vitest-docs/config/cache.md +0 -26
  79. package/vendor/vitest-docs/config/chaiconfig.md +0 -29
  80. package/vendor/vitest-docs/config/clearmocks.md +0 -22
  81. package/vendor/vitest-docs/config/coverage.md +0 -455
  82. package/vendor/vitest-docs/config/css.md +0 -47
  83. package/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
  84. package/vendor/vitest-docs/config/deps.md +0 -127
  85. package/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
  86. package/vendor/vitest-docs/config/diff.md +0 -96
  87. package/vendor/vitest-docs/config/dir.md +0 -7
  88. package/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
  89. package/vendor/vitest-docs/config/env.md +0 -5
  90. package/vendor/vitest-docs/config/environment.md +0 -96
  91. package/vendor/vitest-docs/config/environmentoptions.md +0 -30
  92. package/vendor/vitest-docs/config/exclude.md +0 -49
  93. package/vendor/vitest-docs/config/execargv.md +0 -10
  94. package/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
  95. package/vendor/vitest-docs/config/expect.md +0 -38
  96. package/vendor/vitest-docs/config/experimental.md +0 -510
  97. package/vendor/vitest-docs/config/faketimers.md +0 -51
  98. package/vendor/vitest-docs/config/fileparallelism.md +0 -11
  99. package/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
  100. package/vendor/vitest-docs/config/globals.md +0 -42
  101. package/vendor/vitest-docs/config/globalsetup.md +0 -72
  102. package/vendor/vitest-docs/config/hideskippedtests.md +0 -7
  103. package/vendor/vitest-docs/config/hooktimeout.md +0 -7
  104. package/vendor/vitest-docs/config/include-source.md +0 -115
  105. package/vendor/vitest-docs/config/include.md +0 -71
  106. package/vendor/vitest-docs/config/includetasklocation.md +0 -17
  107. package/vendor/vitest-docs/config/index.md +0 -85
  108. package/vendor/vitest-docs/config/isolate.md +0 -13
  109. package/vendor/vitest-docs/config/logheapusage.md +0 -7
  110. package/vendor/vitest-docs/config/maxconcurrency.md +0 -9
  111. package/vendor/vitest-docs/config/maxworkers.md +0 -49
  112. package/vendor/vitest-docs/config/mockreset.md +0 -22
  113. package/vendor/vitest-docs/config/mode.md +0 -7
  114. package/vendor/vitest-docs/config/name.md +0 -111
  115. package/vendor/vitest-docs/config/onconsolelog.md +0 -25
  116. package/vendor/vitest-docs/config/onstacktrace.md +0 -32
  117. package/vendor/vitest-docs/config/onunhandlederror.md +0 -35
  118. package/vendor/vitest-docs/config/open.md +0 -7
  119. package/vendor/vitest-docs/config/outputfile.md +0 -7
  120. package/vendor/vitest-docs/config/passwithnotests.md +0 -7
  121. package/vendor/vitest-docs/config/pool.md +0 -45
  122. package/vendor/vitest-docs/config/printconsoletrace.md +0 -6
  123. package/vendor/vitest-docs/config/projects.md +0 -6
  124. package/vendor/vitest-docs/config/provide.md +0 -45
  125. package/vendor/vitest-docs/config/reporters.md +0 -69
  126. package/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
  127. package/vendor/vitest-docs/config/restoremocks.md +0 -22
  128. package/vendor/vitest-docs/config/retry.md +0 -140
  129. package/vendor/vitest-docs/config/root.md +0 -6
  130. package/vendor/vitest-docs/config/runner.md +0 -6
  131. package/vendor/vitest-docs/config/sequence.md +0 -158
  132. package/vendor/vitest-docs/config/server.md +0 -68
  133. package/vendor/vitest-docs/config/setupfiles.md +0 -40
  134. package/vendor/vitest-docs/config/silent.md +0 -9
  135. package/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
  136. package/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
  137. package/vendor/vitest-docs/config/snapshotformat.md +0 -28
  138. package/vendor/vitest-docs/config/snapshotserializers.md +0 -6
  139. package/vendor/vitest-docs/config/stricttags.md +0 -30
  140. package/vendor/vitest-docs/config/tags.md +0 -141
  141. package/vendor/vitest-docs/config/teardowntimeout.md +0 -7
  142. package/vendor/vitest-docs/config/testnamepattern.md +0 -21
  143. package/vendor/vitest-docs/config/testtimeout.md +0 -7
  144. package/vendor/vitest-docs/config/typecheck.md +0 -77
  145. package/vendor/vitest-docs/config/ui.md +0 -15
  146. package/vendor/vitest-docs/config/unstubenvs.md +0 -20
  147. package/vendor/vitest-docs/config/unstubglobals.md +0 -20
  148. package/vendor/vitest-docs/config/update.md +0 -16
  149. package/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
  150. package/vendor/vitest-docs/config/watch.md +0 -11
  151. package/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
  152. package/vendor/vitest-docs/guide/advanced/index.md +0 -147
  153. package/vendor/vitest-docs/guide/advanced/pool.md +0 -148
  154. package/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
  155. package/vendor/vitest-docs/guide/advanced/tests.md +0 -125
  156. package/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
  157. package/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
  158. package/vendor/vitest-docs/guide/browser/index.md +0 -630
  159. package/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
  160. package/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
  161. package/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
  162. package/vendor/vitest-docs/guide/cli-generated.md +0 -972
  163. package/vendor/vitest-docs/guide/cli.md +0 -234
  164. package/vendor/vitest-docs/guide/common-errors.md +0 -163
  165. package/vendor/vitest-docs/guide/coverage.md +0 -515
  166. package/vendor/vitest-docs/guide/debugging.md +0 -127
  167. package/vendor/vitest-docs/guide/environment.md +0 -101
  168. package/vendor/vitest-docs/guide/extending-matchers.md +0 -160
  169. package/vendor/vitest-docs/guide/features.md +0 -310
  170. package/vendor/vitest-docs/guide/filtering.md +0 -175
  171. package/vendor/vitest-docs/guide/ide.md +0 -43
  172. package/vendor/vitest-docs/guide/improving-performance.md +0 -245
  173. package/vendor/vitest-docs/guide/in-source.md +0 -159
  174. package/vendor/vitest-docs/guide/index.md +0 -128
  175. package/vendor/vitest-docs/guide/learn/async.md +0 -147
  176. package/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
  177. package/vendor/vitest-docs/guide/learn/matchers.md +0 -277
  178. package/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
  179. package/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
  180. package/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
  181. package/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
  182. package/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
  183. package/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
  184. package/vendor/vitest-docs/guide/lifecycle.md +0 -379
  185. package/vendor/vitest-docs/guide/migration.md +0 -863
  186. package/vendor/vitest-docs/guide/mocking/classes.md +0 -158
  187. package/vendor/vitest-docs/guide/mocking/dates.md +0 -52
  188. package/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
  189. package/vendor/vitest-docs/guide/mocking/functions.md +0 -61
  190. package/vendor/vitest-docs/guide/mocking/globals.md +0 -20
  191. package/vendor/vitest-docs/guide/mocking/modules.md +0 -414
  192. package/vendor/vitest-docs/guide/mocking/requests.md +0 -114
  193. package/vendor/vitest-docs/guide/mocking/timers.md +0 -48
  194. package/vendor/vitest-docs/guide/mocking.md +0 -239
  195. package/vendor/vitest-docs/guide/open-telemetry.md +0 -156
  196. package/vendor/vitest-docs/guide/parallelism.md +0 -82
  197. package/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
  198. package/vendor/vitest-docs/guide/projects.md +0 -291
  199. package/vendor/vitest-docs/guide/recipes.md +0 -59
  200. package/vendor/vitest-docs/guide/reporters.md +0 -723
  201. package/vendor/vitest-docs/guide/snapshot.md +0 -620
  202. package/vendor/vitest-docs/guide/test-annotations.md +0 -103
  203. package/vendor/vitest-docs/guide/test-context.md +0 -902
  204. package/vendor/vitest-docs/guide/test-tags.md +0 -314
  205. package/vendor/vitest-docs/guide/testing-types.md +0 -149
  206. package/vendor/vitest-docs/guide/ui.md +0 -160
  207. package/vendor/vitest-docs/guide/using-plugins.md +0 -5
  208. package/vendor/vitest-docs/manifest.json +0 -1691
@@ -1,1960 +0,0 @@
1
- # assert
2
-
3
- Vitest reexports the `assert` method from [`chai`](https://www.chaijs.com/api/assert/) for verifying invariants.
4
-
5
- ## assert
6
-
7
- - **Type:** `(expression: any, message?: string) => asserts expression`
8
-
9
- Assert that the given `expression` is truthy, otherwise the assertion fails.
10
-
11
- ```ts
12
- import { assert, test } from 'vitest'
13
-
14
- test('assert', () => {
15
- assert('foo' !== 'bar', 'foo should not be equal to bar')
16
- })
17
- ```
18
-
19
- ## fail
20
-
21
- - **Type:**
22
- - `(message?: string) => never`
23
- - `<T>(actual: T, expected: T, message?: string, operator?: string) => never`
24
-
25
- Force an assertion failure.
26
-
27
- ```ts
28
- import { assert, test } from 'vitest'
29
-
30
- test('assert.fail', () => {
31
- assert.fail('error message on failure')
32
- assert.fail('foo', 'bar', 'foo is not bar', '===')
33
- })
34
- ```
35
-
36
- ## isOk
37
-
38
- - **Type:** `<T>(value: T, message?: string) => asserts value`
39
- - **Alias:** `ok`
40
-
41
- Assert that the given `value` is truthy.
42
-
43
- ```ts
44
- import { assert, test } from 'vitest'
45
-
46
- test('assert.isOk', () => {
47
- assert.isOk('foo', 'every truthy is ok')
48
- assert.isOk(false, 'this will fail since false is not truthy')
49
- })
50
- ```
51
-
52
- ## isNotOk
53
-
54
- - **Type:** `<T>(value: T, message?: string) => void`
55
- - **Alias:** `notOk`
56
-
57
- Assert that the given `value` is falsy.
58
-
59
- ```ts
60
- import { assert, test } from 'vitest'
61
-
62
- test('assert.isNotOk', () => {
63
- assert.isNotOk('foo', 'this will fail, every truthy is not ok')
64
- assert.isNotOk(false, 'this will pass since false is falsy')
65
- })
66
- ```
67
-
68
- ## equal
69
-
70
- - **Type:** `<T>(actual: T, expected: T, message?: string) => void`
71
-
72
- Asserts non-strict equality (==) of `actual` and `expected`.
73
-
74
- ```ts
75
- import { assert, test } from 'vitest'
76
-
77
- test('assert.equal', () => {
78
- assert.equal(Math.sqrt(4), '2')
79
- })
80
- ```
81
-
82
- ## notEqual
83
-
84
- - **Type:** `<T>(actual: T, expected: T, message?: string) => void`
85
-
86
- Asserts non-strict inequality (!=) of `actual` and `expected`.
87
-
88
- ```ts
89
- import { assert, test } from 'vitest'
90
-
91
- test('assert.equal', () => {
92
- assert.notEqual(Math.sqrt(4), 3)
93
- })
94
- ```
95
-
96
- ## strictEqual
97
-
98
- - **Type:** `<T>(actual: T, expected: T, message?: string) => void`
99
-
100
- Asserts strict equality (===) of `actual` and `expected`.
101
-
102
- ```ts
103
- import { assert, test } from 'vitest'
104
-
105
- test('assert.strictEqual', () => {
106
- assert.strictEqual(Math.sqrt(4), 2)
107
- })
108
- ```
109
-
110
- ## deepEqual
111
-
112
- - **Type:** `<T>(actual: T, expected: T, message?: string) => void`
113
-
114
- Asserts that `actual` is deeply equal to `expected`.
115
-
116
- ```ts
117
- import { assert, test } from 'vitest'
118
-
119
- test('assert.deepEqual', () => {
120
- assert.deepEqual({ color: 'green' }, { color: 'green' })
121
- })
122
- ```
123
-
124
- ## notDeepEqual
125
-
126
- - **Type:** `<T>(actual: T, expected: T, message?: string) => void`
127
-
128
- Assert that `actual` is not deeply equal to `expected`.
129
-
130
- ```ts
131
- import { assert, test } from 'vitest'
132
-
133
- test('assert.notDeepEqual', () => {
134
- assert.notDeepEqual({ color: 'green' }, { color: 'red' })
135
- })
136
- ```
137
-
138
- ## isAbove
139
-
140
- - **Type:** `(valueToCheck: number, valueToBeAbove: number, message?: string) => void`
141
-
142
- Assert that `valueToCheck` is strictly greater than (>) `valueToBeAbove`.
143
-
144
- ```ts
145
- import { assert, test } from 'vitest'
146
-
147
- test('assert.isAbove', () => {
148
- assert.isAbove(5, 2, '5 is strictly greater than 2')
149
- })
150
- ```
151
-
152
- ## isAtLeast
153
-
154
- - **Type:** `(valueToCheck: number, valueToBeAtLeast: number, message?: string) => void`
155
-
156
- Assert that `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`.
157
-
158
- ```ts
159
- import { assert, test } from 'vitest'
160
-
161
- test('assert.isAtLeast', () => {
162
- assert.isAtLeast(5, 2, '5 is greater or equal to 2')
163
- assert.isAtLeast(3, 3, '3 is greater or equal to 3')
164
- })
165
- ```
166
-
167
- ## isBelow
168
-
169
- - **Type:** `(valueToCheck: number, valueToBeBelow: number, message?: string) => void`
170
-
171
- Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`.
172
-
173
- ```ts
174
- import { assert, test } from 'vitest'
175
-
176
- test('assert.isBelow', () => {
177
- assert.isBelow(3, 6, '3 is strictly less than 6')
178
- })
179
- ```
180
-
181
- ## isAtMost
182
-
183
- - **Type:** `(valueToCheck: number, valueToBeAtMost: number, message?: string) => void`
184
-
185
- Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`.
186
-
187
- ```ts
188
- import { assert, test } from 'vitest'
189
-
190
- test('assert.isAtMost', () => {
191
- assert.isAtMost(3, 6, '3 is less than or equal to 6')
192
- assert.isAtMost(4, 4, '4 is less than or equal to 4')
193
- })
194
- ```
195
-
196
- ## isTrue
197
-
198
- - **Type:** `<T>(value: T, message?: string) => asserts value is true`
199
-
200
- Asserts that `value` is true.
201
-
202
- ```ts
203
- import { assert, test } from 'vitest'
204
-
205
- const testPassed = true
206
-
207
- test('assert.isTrue', () => {
208
- assert.isTrue(testPassed)
209
- })
210
- ```
211
-
212
- ## isNotTrue
213
-
214
- - **Type:** `<T>(value: T, message?: string) => asserts value is Exclude<T, true>`
215
-
216
- Asserts that `value` is not true.
217
-
218
- ```ts
219
- import { assert, test } from 'vitest'
220
-
221
- const testPassed = 'ok'
222
-
223
- test('assert.isNotTrue', () => {
224
- assert.isNotTrue(testPassed)
225
- })
226
- ```
227
-
228
- ## isFalse
229
-
230
- - **Type:** `<T>(value: T, message?: string) => asserts value is false`
231
-
232
- Asserts that `value` is false.
233
-
234
- ```ts
235
- import { assert, test } from 'vitest'
236
-
237
- const testPassed = false
238
-
239
- test('assert.isFalse', () => {
240
- assert.isFalse(testPassed)
241
- })
242
- ```
243
-
244
- ## isNotFalse
245
-
246
- - **Type:** `<T>(value: T, message?: string) => asserts value is Exclude<T, false>`
247
-
248
- Asserts that `value` is not false.
249
-
250
- ```ts
251
- import { assert, test } from 'vitest'
252
-
253
- const testPassed = 'no'
254
-
255
- test('assert.isNotFalse', () => {
256
- assert.isNotFalse(testPassed)
257
- })
258
- ```
259
-
260
- ## isNull
261
-
262
- - **Type:** `<T>(value: T, message?: string) => asserts value is null`
263
-
264
- Asserts that `value` is null.
265
-
266
- ```ts
267
- import { assert, test } from 'vitest'
268
-
269
- const error = null
270
-
271
- test('assert.isNull', () => {
272
- assert.isNull(error, 'error is null')
273
- })
274
- ```
275
-
276
- ## isNotNull
277
-
278
- - **Type:** `<T>(value: T, message?: string) => asserts value is Exclude<T, null>`
279
-
280
- Asserts that `value` is not null.
281
-
282
- ```ts
283
- import { assert, test } from 'vitest'
284
-
285
- const error = { message: 'error was occurred' }
286
-
287
- test('assert.isNotNull', () => {
288
- assert.isNotNull(error, 'error is not null but object')
289
- })
290
- ```
291
-
292
- ## isNaN
293
-
294
- - **Type:** `<T>(value: T, message?: string) => void`
295
-
296
- Asserts that `value` is NaN.
297
-
298
- ```ts
299
- import { assert, test } from 'vitest'
300
-
301
- const calculation = 1 * 'vitest'
302
-
303
- test('assert.isNaN', () => {
304
- assert.isNaN(calculation, '1 * "vitest" is NaN')
305
- })
306
- ```
307
-
308
- ## isNotNaN
309
-
310
- - **Type:** `<T>(value: T, message?: string) => void`
311
-
312
- Asserts that `value` is not NaN.
313
-
314
- ```ts
315
- import { assert, test } from 'vitest'
316
-
317
- const calculation = 1 * 2
318
-
319
- test('assert.isNotNaN', () => {
320
- assert.isNotNaN(calculation, '1 * 2 is Not NaN but 2')
321
- })
322
- ```
323
-
324
- ## exists
325
-
326
- - **Type:** `<T>(value: T, message?: string) => asserts value is NonNullable<T>`
327
-
328
- Asserts that `value` is neither null nor undefined.
329
-
330
- ```ts
331
- import { assert, test } from 'vitest'
332
-
333
- const name = 'foo'
334
-
335
- test('assert.exists', () => {
336
- assert.exists(name, 'foo is neither null nor undefined')
337
- })
338
- ```
339
-
340
- ## notExists
341
-
342
- - **Type:** `<T>(value: T, message?: string) => asserts value is null | undefined`
343
-
344
- Asserts that `value` is either null nor undefined.
345
-
346
- ```ts
347
- import { assert, test } from 'vitest'
348
-
349
- const foo = null
350
- const bar = undefined
351
-
352
- test('assert.notExists', () => {
353
- assert.notExists(foo, 'foo is null so not exist')
354
- assert.notExists(bar, 'bar is undefined so not exist')
355
- })
356
- ```
357
-
358
- ## isUndefined
359
-
360
- - **Type:** `<T>(value: T, message?: string) => asserts value is undefined`
361
-
362
- Asserts that `value` is undefined.
363
-
364
- ```ts
365
- import { assert, test } from 'vitest'
366
-
367
- const name = undefined
368
-
369
- test('assert.isUndefined', () => {
370
- assert.isUndefined(name, 'name is undefined')
371
- })
372
- ```
373
-
374
- ## isDefined
375
-
376
- - **Type:** `<T>(value: T, message?: string) => asserts value is Exclude<T, undefined>`
377
-
378
- Asserts that `value` is not undefined.
379
-
380
- ```ts
381
- import { assert, test } from 'vitest'
382
-
383
- const name = 'foo'
384
-
385
- test('assert.isDefined', () => {
386
- assert.isDefined(name, 'name is not undefined')
387
- })
388
- ```
389
-
390
- ## isFunction
391
-
392
- - **Type:** `<T>(value: T, message?: string) => void`
393
- - **Alias:** `isCallable`
394
- Asserts that `value` is a function.
395
-
396
- ```ts
397
- import { assert, test } from 'vitest'
398
-
399
- function name() { return 'foo' };
400
-
401
- test('assert.isFunction', () => {
402
- assert.isFunction(name, 'name is function')
403
- })
404
- ```
405
-
406
- ## isNotFunction
407
-
408
- - **Type:** `<T>(value: T, message?: string) => void`
409
- - **Alias:** `isNotCallable`
410
-
411
- Asserts that `value` is not a function.
412
-
413
- ```ts
414
- import { assert, test } from 'vitest'
415
-
416
- const name = 'foo'
417
-
418
- test('assert.isNotFunction', () => {
419
- assert.isNotFunction(name, 'name is not function but string')
420
- })
421
- ```
422
-
423
- ## isObject
424
-
425
- - **Type:** `<T>(value: T, message?: string) => void`
426
-
427
- Asserts that `value` is an object of type Object (as revealed by Object.prototype.toString). The assertion does not match subclassed objects.
428
-
429
- ```ts
430
- import { assert, test } from 'vitest'
431
-
432
- const someThing = { color: 'red', shape: 'circle' }
433
-
434
- test('assert.isObject', () => {
435
- assert.isObject(someThing, 'someThing is object')
436
- })
437
- ```
438
-
439
- ## isNotObject
440
-
441
- - **Type:** `<T>(value: T, message?: string) => void`
442
-
443
- Asserts that `value` is not an object of type Object (as revealed by Object.prototype.toString). The assertion does not match subclassed objects.
444
-
445
- ```ts
446
- import { assert, test } from 'vitest'
447
-
448
- const someThing = 'redCircle'
449
-
450
- test('assert.isNotObject', () => {
451
- assert.isNotObject(someThing, 'someThing is not object but string')
452
- })
453
- ```
454
-
455
- ## isArray
456
-
457
- - **Type:** `<T>(value: T, message?: string) => void`
458
-
459
- Asserts that `value` is an array.
460
-
461
- ```ts
462
- import { assert, test } from 'vitest'
463
-
464
- const color = ['red', 'green', 'yellow']
465
-
466
- test('assert.isArray', () => {
467
- assert.isArray(color, 'color is array')
468
- })
469
- ```
470
-
471
- ## isNotArray
472
-
473
- - **Type:** `<T>(value: T, message?: string) => void`
474
-
475
- Asserts that `value` is not an array.
476
-
477
- ```ts
478
- import { assert, test } from 'vitest'
479
-
480
- const color = 'red'
481
-
482
- test('assert.isNotArray', () => {
483
- assert.isNotArray(color, 'color is not array but string')
484
- })
485
- ```
486
-
487
- ## isString
488
-
489
- - **Type:** `<T>(value: T, message?: string) => void`
490
-
491
- Asserts that `value` is a string.
492
-
493
- ```ts
494
- import { assert, test } from 'vitest'
495
-
496
- const color = 'red'
497
-
498
- test('assert.isString', () => {
499
- assert.isString(color, 'color is string')
500
- })
501
- ```
502
-
503
- ## isNotString
504
-
505
- - **Type:** `<T>(value: T, message?: string) => void`
506
-
507
- Asserts that `value` is not a string.
508
-
509
- ```ts
510
- import { assert, test } from 'vitest'
511
-
512
- const color = ['red', 'green', 'yellow']
513
-
514
- test('assert.isNotString', () => {
515
- assert.isNotString(color, 'color is not string but array')
516
- })
517
- ```
518
-
519
- ## isNumber
520
-
521
- - **Type:** `<T>(value: T, message?: string) => void`
522
-
523
- Asserts that `value` is a number.
524
-
525
- ```ts
526
- import { assert, test } from 'vitest'
527
-
528
- const colors = 3
529
-
530
- test('assert.isNumber', () => {
531
- assert.isNumber(colors, 'colors is number')
532
- })
533
- ```
534
-
535
- ## isNotNumber
536
-
537
- - **Type:** `<T>(value: T, message?: string) => void`
538
-
539
- Asserts that `value` is not a number.
540
-
541
- ```ts
542
- import { assert, test } from 'vitest'
543
-
544
- const colors = '3 colors'
545
-
546
- test('assert.isNotNumber', () => {
547
- assert.isNotNumber(colors, 'colors is not number but strings')
548
- })
549
- ```
550
-
551
- ## isFinite
552
-
553
- - **Type:** `<T>(value: T, message?: string) => void`
554
-
555
- Asserts that `value` is a finite number (not NaN, Infinity).
556
-
557
- ```ts
558
- import { assert, test } from 'vitest'
559
-
560
- const colors = 3
561
-
562
- test('assert.isFinite', () => {
563
- assert.isFinite(colors, 'colors is number not NaN or Infinity')
564
- })
565
- ```
566
-
567
- ## isBoolean
568
-
569
- - **Type:** `<T>(value: T, message?: string) => void`
570
-
571
- Asserts that `value` is a boolean.
572
-
573
- ```ts
574
- import { assert, test } from 'vitest'
575
-
576
- const isReady = true
577
-
578
- test('assert.isBoolean', () => {
579
- assert.isBoolean(isReady, 'isReady is a boolean')
580
- })
581
- ```
582
-
583
- ## isNotBoolean
584
-
585
- - **Type:** `<T>(value: T, message?: string) => void`
586
-
587
- Asserts that `value` is not a boolean.
588
-
589
- ```ts
590
- import { assert, test } from 'vitest'
591
-
592
- const isReady = 'sure'
593
-
594
- test('assert.isBoolean', () => {
595
- assert.isBoolean(isReady, 'isReady is not a boolean but string')
596
- })
597
- ```
598
-
599
- ## typeOf
600
-
601
- - **Type:** `<T>(value: T, name: string, message?: string) => void`
602
-
603
- Asserts that `value`’s type is `name`, as determined by Object.prototype.toString.
604
-
605
- ```ts
606
- import { assert, test } from 'vitest'
607
-
608
- test('assert.typeOf', () => {
609
- assert.typeOf({ color: 'red' }, 'object', 'we have an object')
610
- assert.typeOf(['red', 'green'], 'array', 'we have an array')
611
- assert.typeOf('red', 'string', 'we have a string')
612
- assert.typeOf(/red/, 'regexp', 'we have a regular expression')
613
- assert.typeOf(null, 'null', 'we have a null')
614
- assert.typeOf(undefined, 'undefined', 'we have an undefined')
615
- })
616
- ```
617
-
618
- ## notTypeOf
619
-
620
- - **Type:** `<T>(value: T, name: string, message?: string) => void`
621
-
622
- Asserts that `value`’s type is not `name`, as determined by Object.prototype.toString.
623
-
624
- ```ts
625
- import { assert, test } from 'vitest'
626
-
627
- test('assert.notTypeOf', () => {
628
- assert.notTypeOf('red', 'number', '"red" is not a number')
629
- })
630
- ```
631
-
632
- ## instanceOf
633
-
634
- - **Type:** `<T>(value: T, constructor: Function, message?: string) => asserts value is T`
635
-
636
- Asserts that `value` is an instance of `constructor`.
637
-
638
- ```ts
639
- import { assert, test } from 'vitest'
640
-
641
- function Person(name) { this.name = name }
642
- const foo = new Person('foo')
643
-
644
- class Tea {
645
- constructor(name) {
646
- this.name = name
647
- }
648
- }
649
- const coffee = new Tea('coffee')
650
-
651
- test('assert.instanceOf', () => {
652
- assert.instanceOf(foo, Person, 'foo is an instance of Person')
653
- assert.instanceOf(coffee, Tea, 'coffee is an instance of Tea')
654
- })
655
- ```
656
-
657
- ## notInstanceOf
658
-
659
- - **Type:** `<T>(value: T, constructor: Function, message?: string) => asserts value is Exclude<T, U>`
660
-
661
- Asserts that `value` is not an instance of `constructor`.
662
-
663
- ```ts
664
- import { assert, test } from 'vitest'
665
-
666
- function Person(name) { this.name = name }
667
- const foo = new Person('foo')
668
-
669
- class Tea {
670
- constructor(name) {
671
- this.name = name
672
- }
673
- }
674
- const coffee = new Tea('coffee')
675
-
676
- test('assert.instanceOf', () => {
677
- assert.instanceOf(foo, Tea, 'foo is not an instance of Tea')
678
- })
679
- ```
680
-
681
- ## include
682
-
683
- - **Type:**
684
- - `(haystack: string, needle: string, message?: string) => void`
685
- - `<T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void`
686
- - `<T extends object>(haystack: WeakSet<T>, needle: T, message?: string) => void`
687
- - `<T>(haystack: T, needle: Partial<T>, message?: string) => void`
688
-
689
- Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a value in an array, a substring in a string, or a subset of properties in an object.
690
-
691
- ```ts
692
- import { assert, test } from 'vitest'
693
-
694
- test('assert.include', () => {
695
- assert.include([1, 2, 3], 2, 'array contains value')
696
- assert.include('foobar', 'foo', 'string contains substring')
697
- assert.include({ foo: 'bar', hello: 'universe' }, { foo: 'bar' }, 'object contains property')
698
- })
699
- ```
700
-
701
- ## notInclude
702
-
703
- - **Type:**
704
- - `(haystack: string, needle: string, message?: string) => void`
705
- - `<T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void`
706
- - `<T extends object>(haystack: WeakSet<T>, needle: T, message?: string) => void`
707
- - `<T>(haystack: T, needle: Partial<T>, message?: string) => void`
708
-
709
- Asserts that `haystack` does not include `needle`. It can be used to assert the absence of a value in an array, a substring in a string, or a subset of properties in an object.
710
-
711
- ```ts
712
- import { assert, test } from 'vitest'
713
-
714
- test('assert.notInclude', () => {
715
- assert.notInclude([1, 2, 3], 4, 'array doesn\'t contain 4')
716
- assert.notInclude('foobar', 'baz', 'foobar doesn\'t contain baz')
717
- assert.notInclude({ foo: 'bar', hello: 'universe' }, { foo: 'baz' }, 'object doesn\'t contain property')
718
- })
719
- ```
720
-
721
- ## deepInclude
722
-
723
- - **Type:**
724
- - `(haystack: string, needle: string, message?: string) => void`
725
- - `<T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void`
726
- - `<T>(haystack: T, needle: T extends WeakSet<any> ? never : Partial<T>, message?: string) => void`
727
-
728
- Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a value in an array or a subset of properties in an object. Deep equality is used.
729
-
730
- ```ts
731
- import { assert, test } from 'vitest'
732
-
733
- const obj1 = { a: 1 }
734
- const obj2 = { b: 2 }
735
-
736
- test('assert.deepInclude', () => {
737
- assert.deepInclude([obj1, obj2], { a: 1 })
738
- assert.deepInclude({ foo: obj1, bar: obj2 }, { foo: { a: 1 } })
739
- })
740
- ```
741
-
742
- ## notDeepInclude
743
-
744
- - **Type:**
745
- - `(haystack: string, needle: string, message?: string) => void`
746
- - `<T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void`
747
- - `<T>(haystack: T, needle: T extends WeakSet<any> ? never : Partial<T>, message?: string) => void`
748
-
749
- Asserts that `haystack` does not include `needle`. It can be used to assert the absence of a value in an array or a subset of properties in an object. Deep equality is used.
750
-
751
- ```ts
752
- import { assert, test } from 'vitest'
753
-
754
- const obj1 = { a: 1 }
755
- const obj2 = { b: 2 }
756
-
757
- test('assert.notDeepInclude', () => {
758
- assert.notDeepInclude([obj1, obj2], { a: 10 })
759
- assert.notDeepInclude({ foo: obj1, bar: obj2 }, { foo: { a: 10 } })
760
- })
761
- ```
762
-
763
- ## nestedInclude
764
-
765
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
766
-
767
- Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
768
-
769
- ```ts
770
- import { assert, test } from 'vitest'
771
-
772
- test('assert.nestedInclude', () => {
773
- assert.nestedInclude({ '.a': { b: 'x' } }, { '\\.a.[b]': 'x' })
774
- assert.nestedInclude({ a: { '[b]': 'x' } }, { 'a.\\[b\\]': 'x' })
775
- })
776
- ```
777
-
778
- ## notNestedInclude
779
-
780
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
781
-
782
- Asserts that `haystack` does not include `needle`. Can be used to assert the inclusion of a subset of properties in an object. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
783
-
784
- ```ts
785
- import { assert, test } from 'vitest'
786
-
787
- test('assert.nestedInclude', () => {
788
- assert.notNestedInclude({ '.a': { b: 'x' } }, { '\\.a.b': 'y' })
789
- assert.notNestedInclude({ a: { '[b]': 'x' } }, { 'a.\\[b\\]': 'y' })
790
- })
791
- ```
792
-
793
- ## deepNestedInclude
794
-
795
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
796
-
797
- Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object while checking for deep equality. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
798
-
799
- ```ts
800
- import { assert, test } from 'vitest'
801
-
802
- test('assert.deepNestedInclude', () => {
803
- assert.deepNestedInclude({ a: { b: [{ x: 1 }] } }, { 'a.b[0]': { x: 1 } })
804
- assert.deepNestedInclude({ '.a': { '[b]': { x: 1 } } }, { '\\.a.\\[b\\]': { x: 1 } })
805
- })
806
- ```
807
-
808
- ## notDeepNestedInclude
809
-
810
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
811
-
812
- Asserts that `haystack` not includes `needle`. Can be used to assert the absence of a subset of properties in an object while checking for deep equality. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
813
-
814
- ```ts
815
- import { assert, test } from 'vitest'
816
-
817
- test('assert.notDeepNestedInclude', () => {
818
- assert.notDeepNestedInclude({ a: { b: [{ x: 1 }] } }, { 'a.b[0]': { y: 1 } })
819
- assert.notDeepNestedInclude({ '.a': { '[b]': { x: 1 } } }, { '\\.a.\\[b\\]': { y: 2 } })
820
- })
821
- ```
822
-
823
- ## ownInclude
824
-
825
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
826
-
827
- Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object while ignoring inherited properties.
828
-
829
- ```ts
830
- import { assert, test } from 'vitest'
831
-
832
- test('assert.ownInclude', () => {
833
- assert.ownInclude({ a: 1 }, { a: 1 })
834
- })
835
- ```
836
-
837
- ## notOwnInclude
838
-
839
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
840
-
841
- Asserts that `haystack` includes `needle`. Can be used to assert the absence of a subset of properties in an object while ignoring inherited properties.
842
-
843
- ```ts
844
- import { assert, test } from 'vitest'
845
-
846
- const obj1 = {
847
- b: 2
848
- }
849
-
850
- const obj2 = object.create(obj1)
851
- obj2.a = 1
852
-
853
- test('assert.notOwnInclude', () => {
854
- assert.notOwnInclude(obj2, { b: 2 })
855
- })
856
- ```
857
-
858
- ## deepOwnInclude
859
-
860
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
861
-
862
- Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object while ignoring inherited properties and checking for deep equality.
863
-
864
- ```ts
865
- import { assert, test } from 'vitest'
866
-
867
- test('assert.deepOwnInclude', () => {
868
- assert.deepOwnInclude({ a: { b: 2 } }, { a: { b: 2 } })
869
- })
870
- ```
871
-
872
- ## notDeepOwnInclude
873
-
874
- - **Type:** `(haystack: any, needle: any, message?: string) => void`
875
-
876
- Asserts that `haystack` not includes `needle`. Can be used to assert the absence of a subset of properties in an object while ignoring inherited properties and checking for deep equality.
877
-
878
- ```ts
879
- import { assert, test } from 'vitest'
880
-
881
- test('assert.notDeepOwnInclude', () => {
882
- assert.notDeepOwnInclude({ a: { b: 2 } }, { a: { c: 3 } })
883
- })
884
- ```
885
-
886
- ## match
887
-
888
- - **Type:** `(value: string, regexp: RegExp, message?: string) => void`
889
-
890
- Asserts that `value` matches the regular expression `regexp`.
891
-
892
- ```ts
893
- import { assert, test } from 'vitest'
894
-
895
- test('assert.match', () => {
896
- assert.match('foobar', /^foo/, 'regexp matches')
897
- })
898
- ```
899
-
900
- ## notMatch
901
-
902
- - **Type:** `(value: string, regexp: RegExp, message?: string) => void`
903
-
904
- Asserts that `value` does not matches the regular expression `regexp`.
905
-
906
- ```ts
907
- import { assert, test } from 'vitest'
908
-
909
- test('assert.notMatch', () => {
910
- assert.notMatch('foobar', /^foo/, 'regexp does not match')
911
- })
912
- ```
913
-
914
- ## property
915
-
916
- - **Type:** `<T>(object: T, property: string, message?: string) => void`
917
-
918
- Asserts that `object` has a direct or inherited property named by `property`
919
-
920
- ```ts
921
- import { assert, test } from 'vitest'
922
-
923
- test('assert.property', () => {
924
- assert.property({ tea: { green: 'matcha' } }, 'tea')
925
- assert.property({ tea: { green: 'matcha' } }, 'toString')
926
- })
927
- ```
928
-
929
- ## notProperty
930
-
931
- - **Type:** `<T>(object: T, property: string, message?: string) => void`
932
-
933
- Asserts that `object` does not have a direct or inherited property named by `property`
934
-
935
- ```ts
936
- import { assert, test } from 'vitest'
937
-
938
- test('assert.notProperty', () => {
939
- assert.notProperty({ tea: { green: 'matcha' } }, 'coffee')
940
- })
941
- ```
942
-
943
- ## propertyVal
944
-
945
- - **Type:** `<T, V>(object: T, property: string, value: V, message?: string) => void`
946
-
947
- Asserts that `object` has a direct or inherited property named by `property` with a value given by `value`. Uses a strict equality check (===).
948
-
949
- ```ts
950
- import { assert, test } from 'vitest'
951
-
952
- test('assert.notPropertyVal', () => {
953
- assert.propertyVal({ tea: 'is good' }, 'tea', 'is good')
954
- })
955
- ```
956
-
957
- ## notPropertyVal
958
-
959
- - **Type:** `<T, V>(object: T, property: string, value: V, message?: string) => void`
960
-
961
- Asserts that `object` does not have a direct or inherited property named by `property` with a value given by `value`. Uses a strict equality check (===).
962
-
963
- ```ts
964
- import { assert, test } from 'vitest'
965
-
966
- test('assert.notPropertyVal', () => {
967
- assert.notPropertyVal({ tea: 'is good' }, 'tea', 'is bad')
968
- assert.notPropertyVal({ tea: 'is good' }, 'coffee', 'is good')
969
- })
970
- ```
971
-
972
- ## deepPropertyVal
973
-
974
- - **Type:** `<T, V>(object: T, property: string, value: V, message?: string) => void`
975
-
976
- Asserts that `object` has a direct or inherited property named by `property` with a value given by `value`. Uses a deep equality check.
977
-
978
- ```ts
979
- import { assert, test } from 'vitest'
980
-
981
- test('assert.deepPropertyVal', () => {
982
- assert.deepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' })
983
- })
984
- ```
985
-
986
- ## notDeepPropertyVal
987
-
988
- - **Type:** `<T, V>(object: T, property: string, value: V, message?: string) => void`
989
-
990
- Asserts that `object` does not have a direct or inherited property named by `property` with a value given by `value`. Uses a deep equality check.
991
-
992
- ```ts
993
- import { assert, test } from 'vitest'
994
-
995
- test('assert.deepPropertyVal', () => {
996
- assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' })
997
- assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' })
998
- assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' })
999
- })
1000
- ```
1001
-
1002
- ## nestedProperty
1003
-
1004
- - **Type:** `<T>(object: T, property: string, message?: string) => void`
1005
-
1006
- Asserts that `object` has a direct or inherited property named by `property`, which can be a string using dot- and bracket-notation for nested reference.
1007
-
1008
- ```ts
1009
- import { assert, test } from 'vitest'
1010
-
1011
- test('assert.deepPropertyVal', () => {
1012
- assert.nestedProperty({ tea: { green: 'matcha' } }, 'tea.green')
1013
- })
1014
- ```
1015
-
1016
- ## notNestedProperty
1017
-
1018
- - **Type:** `<T>(object: T, property: string, message?: string) => void`
1019
-
1020
- Asserts that `object` does not have a direct or inherited property named by `property`, which can be a string using dot- and bracket-notation for nested reference.
1021
-
1022
- ```ts
1023
- import { assert, test } from 'vitest'
1024
-
1025
- test('assert.deepPropertyVal', () => {
1026
- assert.notNestedProperty({ tea: { green: 'matcha' } }, 'tea.oolong')
1027
- })
1028
- ```
1029
-
1030
- ## nestedPropertyVal
1031
-
1032
- - **Type:** `<T>(object: T, property: string, value: any, message?: string) => void`
1033
-
1034
- Asserts that `object` has a property named by `property` with value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a strict equality check (===).
1035
-
1036
- ```ts
1037
- import { assert, test } from 'vitest'
1038
-
1039
- test('assert.nestedPropertyVal', () => {
1040
- assert.nestedPropertyVal({ tea: { green: 'matcha' } }, 'tea.green', 'matcha')
1041
- })
1042
- ```
1043
-
1044
- ## notNestedPropertyVal
1045
-
1046
- - **Type:** `<T>(object: T, property: string, value: any, message?: string) => void`
1047
-
1048
- Asserts that `object` does not have a property named by `property` with value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a strict equality check (===).
1049
-
1050
- ```ts
1051
- import { assert, test } from 'vitest'
1052
-
1053
- test('assert.notNestedPropertyVal', () => {
1054
- assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'tea.green', 'konacha')
1055
- assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'coffee.green', 'matcha')
1056
- })
1057
- ```
1058
-
1059
- ## deepNestedPropertyVal
1060
-
1061
- - **Type:** `<T>(object: T, property: string, value: any, message?: string) => void`
1062
-
1063
- Asserts that `object` has a property named by `property` with a value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a deep equality check (===).
1064
-
1065
- ```ts
1066
- import { assert, test } from 'vitest'
1067
-
1068
- test('assert.notNestedPropertyVal', () => {
1069
- assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'tea.green', 'konacha')
1070
- assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'coffee.green', 'matcha')
1071
- })
1072
- ```
1073
-
1074
- ## notDeepNestedPropertyVal
1075
-
1076
- - **Type:** `<T>(object: T, property: string, value: any, message?: string) => void`
1077
-
1078
- Asserts that `object` does not have a property named by `property` with value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a deep equality check.
1079
-
1080
- ```ts
1081
- import { assert, test } from 'vitest'
1082
-
1083
- test('assert.notDeepNestedPropertyVal', () => {
1084
- assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { oolong: 'yum' })
1085
- assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yuck' })
1086
- assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.black', { matcha: 'yum' })
1087
- })
1088
- ```
1089
-
1090
- ## lengthOf
1091
-
1092
- - **Type:** `<T extends { readonly length?: number | undefined } | { readonly size?: number | undefined }>(object: T, length: number, message?: string) => void`
1093
-
1094
- Asserts that `object` has a `length` or `size` with the expected value.
1095
-
1096
- ```ts
1097
- import { assert, test } from 'vitest'
1098
-
1099
- test('assert.lengthOf', () => {
1100
- assert.lengthOf([1, 2, 3], 3, 'array has length of 3')
1101
- assert.lengthOf('foobar', 6, 'string has length of 6')
1102
- assert.lengthOf(new Set([1, 2, 3]), 3, 'set has size of 3')
1103
- assert.lengthOf(new Map([['a', 1], ['b', 2], ['c', 3]]), 3, 'map has size of 3')
1104
- })
1105
- ```
1106
-
1107
- ## hasAnyKeys
1108
-
1109
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1110
-
1111
- Asserts that `object` has at least one of the `keys` provided. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1112
-
1113
- ```ts
1114
- import { assert, test } from 'vitest'
1115
-
1116
- test('assert.hasAnyKeys', () => {
1117
- assert.hasAnyKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'iDontExist', 'baz'])
1118
- assert.hasAnyKeys({ foo: 1, bar: 2, baz: 3 }, { foo: 30, iDontExist: 99, baz: 1337 })
1119
- assert.hasAnyKeys(new Map([[{ foo: 1 }, 'bar'], ['key', 'value']]), [{ foo: 1 }, 'key'])
1120
- assert.hasAnyKeys(new Set([{ foo: 'bar' }, 'anotherKey']), [{ foo: 'bar' }, 'anotherKey'])
1121
- })
1122
- ```
1123
-
1124
- ## hasAllKeys
1125
-
1126
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1127
-
1128
- Asserts that `object` has all and only all of the `keys` provided. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1129
-
1130
- ```ts
1131
- import { assert, test } from 'vitest'
1132
-
1133
- test('assert.hasAllKeys', () => {
1134
- assert.hasAllKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar', 'baz'])
1135
- assert.hasAllKeys({ foo: 1, bar: 2, baz: 3 }, { foo: 30, bar: 99, baz: 1337 })
1136
- assert.hasAllKeys(new Map([[{ foo: 1 }, 'bar'], ['key', 'value']]), [{ foo: 1 }, 'key'])
1137
- assert.hasAllKeys(new Set([{ foo: 'bar' }, 'anotherKey'], [{ foo: 'bar' }, 'anotherKey']))
1138
- })
1139
- ```
1140
-
1141
- ## containsAllKeys
1142
-
1143
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1144
-
1145
- Asserts that `object` has all of the `keys` provided but may have more keys not listed. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1146
-
1147
- ```ts
1148
- import { assert, test } from 'vitest'
1149
-
1150
- test('assert.containsAllKeys', () => {
1151
- assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'baz'])
1152
- assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar', 'baz'])
1153
- assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, { foo: 30, baz: 1337 })
1154
- assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, { foo: 30, bar: 99, baz: 1337 })
1155
- assert.containsAllKeys(new Map([[{ foo: 1 }, 'bar'], ['key', 'value']]), [{ foo: 1 }])
1156
- assert.containsAllKeys(new Map([[{ foo: 1 }, 'bar'], ['key', 'value']]), [{ foo: 1 }, 'key'])
1157
- assert.containsAllKeys(new Set([{ foo: 'bar' }, 'anotherKey'], [{ foo: 'bar' }]))
1158
- assert.containsAllKeys(new Set([{ foo: 'bar' }, 'anotherKey'], [{ foo: 'bar' }, 'anotherKey']))
1159
- })
1160
- ```
1161
-
1162
- ## doesNotHaveAnyKeys
1163
-
1164
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1165
-
1166
- Asserts that `object` has none of the `keys` provided. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1167
-
1168
- ```ts
1169
- import { assert, test } from 'vitest'
1170
-
1171
- test('assert.doesNotHaveAnyKeys', () => {
1172
- assert.doesNotHaveAnyKeys({ foo: 1, bar: 2, baz: 3 }, ['one', 'two', 'example'])
1173
- assert.doesNotHaveAnyKeys({ foo: 1, bar: 2, baz: 3 }, { one: 1, two: 2, example: 'foo' })
1174
- assert.doesNotHaveAnyKeys(new Map([[{ foo: 1 }, 'bar'], ['key', 'value']]), [{ one: 'two' }, 'example'])
1175
- assert.doesNotHaveAnyKeys(new Set([{ foo: 'bar' }, 'anotherKey'], [{ one: 'two' }, 'example']))
1176
- })
1177
- ```
1178
-
1179
- ## doesNotHaveAllKeys
1180
-
1181
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1182
-
1183
- Asserts that `object` does not have at least one of the `keys` provided. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1184
-
1185
- ```ts
1186
- import { assert, test } from 'vitest'
1187
-
1188
- test('assert.hasAnyKeys', () => {
1189
- assert.doesNotHaveAnyKeys({ foo: 1, bar: 2, baz: 3 }, ['one', 'two', 'example'])
1190
- assert.doesNotHaveAnyKeys({ foo: 1, bar: 2, baz: 3 }, { one: 1, two: 2, example: 'foo' })
1191
- assert.doesNotHaveAnyKeys(new Map([[{ foo: 1 }, 'bar'], ['key', 'value']]), [{ one: 'two' }, 'example'])
1192
- assert.doesNotHaveAnyKeys(new Set([{ foo: 'bar' }, 'anotherKey']), [{ one: 'two' }, 'example'])
1193
- })
1194
- ```
1195
-
1196
- ## hasAnyDeepKeys
1197
-
1198
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1199
-
1200
- Asserts that `object` has at least one of the `keys` provided. Since Sets and Maps can have objects as keys you can use this assertion to perform a deep comparison. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1201
-
1202
- ```ts
1203
- import { assert, test } from 'vitest'
1204
-
1205
- test('assert.hasAnyDeepKeys', () => {
1206
- assert.hasAnyDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [1, 2]]), { one: 'one' })
1207
- assert.hasAnyDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [1, 2]]), [{ one: 'one' }, { two: 'two' }])
1208
- assert.hasAnyDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [{ two: 'two' }, 'valueTwo']]), [{ one: 'one' }, { two: 'two' }])
1209
- assert.hasAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), { one: 'one' })
1210
- assert.hasAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [{ one: 'one' }, { three: 'three' }])
1211
- assert.hasAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [{ one: 'one' }, { two: 'two' }])
1212
- })
1213
- ```
1214
-
1215
- ## hasAllDeepKeys
1216
-
1217
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1218
-
1219
- Asserts that `object` has all and only all of the `keys` provided. Since Sets and Maps can have objects as keys you can use this assertion to perform a deep comparison. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1220
-
1221
- ```ts
1222
- import { assert, test } from 'vitest'
1223
-
1224
- test('assert.hasAnyDeepKeys', () => {
1225
- assert.hasAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne']]), { one: 'one' })
1226
- assert.hasAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [{ two: 'two' }, 'valueTwo']]), [{ one: 'one' }, { two: 'two' }])
1227
- assert.hasAllDeepKeys(new Set([{ one: 'one' }]), { one: 'one' })
1228
- assert.hasAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [{ one: 'one' }, { two: 'two' }])
1229
- })
1230
- ```
1231
-
1232
- ## containsAllDeepKeys
1233
-
1234
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1235
-
1236
- Asserts that `object` contains all of the `keys` provided. Since Sets and Maps can have objects as keys you can use this assertion to perform a deep comparison. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1237
-
1238
- ```ts
1239
- import { assert, test } from 'vitest'
1240
-
1241
- test('assert.containsAllDeepKeys', () => {
1242
- assert.containsAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [1, 2]]), { one: 'one' })
1243
- assert.containsAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [{ two: 'two' }, 'valueTwo']]), [{ one: 'one' }, { two: 'two' }])
1244
- assert.containsAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), { one: 'one' })
1245
- assert.containsAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [{ one: 'one' }, { two: 'two' }])
1246
- })
1247
- ```
1248
-
1249
- ## doesNotHaveAnyDeepKeys
1250
-
1251
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1252
-
1253
- Asserts that `object` has none of the `keys` provided. Since Sets and Maps can have objects as keys you can use this assertion to perform a deep comparison. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1254
-
1255
- ```ts
1256
- import { assert, test } from 'vitest'
1257
-
1258
- test('assert.doesNotHaveAnyDeepKeys', () => {
1259
- assert.doesNotHaveAnyDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [1, 2]]), { thisDoesNot: 'exist' })
1260
- assert.doesNotHaveAnyDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [{ two: 'two' }, 'valueTwo']]), [{ twenty: 'twenty' }, { fifty: 'fifty' }])
1261
- assert.doesNotHaveAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), { twenty: 'twenty' })
1262
- assert.doesNotHaveAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [{ twenty: 'twenty' }, { fifty: 'fifty' }])
1263
- })
1264
- ```
1265
-
1266
- ## doesNotHaveAllDeepKeys
1267
-
1268
- - **Type:** `<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void`
1269
-
1270
- Asserts that `object` does not have at least one of the `keys` provided. Since Sets and Maps can have objects as keys you can use this assertion to perform a deep comparison. You can also provide a single object instead of a keys array and its keys will be used as the expected set of keys.
1271
-
1272
- ```ts
1273
- import { assert, test } from 'vitest'
1274
-
1275
- test('assert.doesNotHaveAllDeepKeys', () => {
1276
- assert.doesNotHaveAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [1, 2]]), { thisDoesNot: 'exist' })
1277
- assert.doesNotHaveAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne'], [{ two: 'two' }, 'valueTwo']]), [{ twenty: 'twenty' }, { one: 'one' }])
1278
- assert.doesNotHaveAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), { twenty: 'twenty' })
1279
- assert.doesNotHaveAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [{ one: 'one' }, { fifty: 'fifty' }])
1280
- })
1281
- ```
1282
-
1283
- ## throws
1284
-
1285
- - **Type:**
1286
- - `(fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string) => void`
1287
- - `(fn: () => void, errorLike?: ErrorConstructor | Error | null, errMsgMatcher?: RegExp | string | null, message?: string) => void`
1288
- - **Alias:**
1289
- - `throw`
1290
- - `Throw`
1291
-
1292
- If `errorLike` is an Error constructor, asserts that `fn` will throw an error that is an instance of `errorLike`. If errorLike is an Error instance, asserts that the error thrown is the same instance as `errorLike`. If `errMsgMatcher` is provided, it also asserts that the error thrown will have a message matching `errMsgMatcher`.
1293
-
1294
- ```ts
1295
- import { assert, test } from 'vitest'
1296
-
1297
- test('assert.throws', () => {
1298
- assert.throws(fn, 'Error thrown must have this msg')
1299
- assert.throws(fn, /Error thrown must have a msg that matches this/)
1300
- assert.throws(fn, ReferenceError)
1301
- assert.throws(fn, errorInstance)
1302
- assert.throws(fn, ReferenceError, 'Error thrown must be a ReferenceError and have this msg')
1303
- assert.throws(fn, errorInstance, 'Error thrown must be the same errorInstance and have this msg')
1304
- assert.throws(fn, ReferenceError, /Error thrown must be a ReferenceError and match this/)
1305
- assert.throws(fn, errorInstance, /Error thrown must be the same errorInstance and match this/)
1306
- })
1307
- ```
1308
-
1309
- ## doesNotThrow
1310
-
1311
- - **Type:** `(fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string) => void`
1312
- - **Type:** `(fn: () => void, errorLike?: ErrorConstructor | Error | null, errMsgMatcher?: RegExp | string | null, message?: string) => void`
1313
-
1314
- If `errorLike` is an Error constructor, asserts that `fn` will not throw an error that is an instance of `errorLike`. If errorLike is an Error instance, asserts that the error thrown is not the same instance as `errorLike`. If `errMsgMatcher` is provided, it also asserts that the error thrown will not have a message matching `errMsgMatcher`.
1315
-
1316
- ```ts
1317
- import { assert, test } from 'vitest'
1318
-
1319
- test('assert.doesNotThrow', () => {
1320
- assert.doesNotThrow(fn, 'Any Error thrown must not have this message')
1321
- assert.doesNotThrow(fn, /Any Error thrown must not match this/)
1322
- assert.doesNotThrow(fn, Error)
1323
- assert.doesNotThrow(fn, errorInstance)
1324
- assert.doesNotThrow(fn, Error, 'Error must not have this message')
1325
- assert.doesNotThrow(fn, errorInstance, 'Error must not have this message')
1326
- assert.doesNotThrow(fn, Error, /Error must not match this/)
1327
- assert.doesNotThrow(fn, errorInstance, /Error must not match this/)
1328
- })
1329
- ```
1330
-
1331
- ## operator
1332
-
1333
- - **Type:** `(val1: OperatorComparable, operator: Operator, val2: OperatorComparable, message?: string) => void`
1334
-
1335
- Compare `val1` and `val2` using `operator`.
1336
-
1337
- ```ts
1338
- import { assert, test } from 'vitest'
1339
-
1340
- test('assert.operator', () => {
1341
- assert.operator(1, '<', 2, 'everything is ok')
1342
- })
1343
- ```
1344
-
1345
- ## closeTo
1346
-
1347
- - **Type:** `(actual: number, expected: number, delta: number, message?: string) => void`
1348
- - **Alias:** `approximately`
1349
-
1350
- Asserts that the `actual` is equal `expected`, to within a +/- `delta` range.
1351
-
1352
- ```ts
1353
- import { assert, test } from 'vitest'
1354
-
1355
- test('assert.closeTo', () => {
1356
- assert.closeTo(1.5, 1, 0.5, 'numbers are close')
1357
- })
1358
- ```
1359
-
1360
- ## sameMembers
1361
-
1362
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1363
-
1364
- Asserts that `set1` and `set2` have the same members in any order. Uses a strict equality check (===).
1365
-
1366
- ```ts
1367
- import { assert, test } from 'vitest'
1368
-
1369
- test('assert.sameMembers', () => {
1370
- assert.sameMembers([1, 2, 3], [2, 1, 3], 'same members')
1371
- })
1372
- ```
1373
-
1374
- ## notSameMembers
1375
-
1376
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1377
-
1378
- Asserts that `set1` and `set2` don't have the same members in any order. Uses a strict equality check (===).
1379
-
1380
- ```ts
1381
- import { assert, test } from 'vitest'
1382
-
1383
- test('assert.sameMembers', () => {
1384
- assert.notSameMembers([1, 2, 3], [5, 1, 3], 'not same members')
1385
- })
1386
- ```
1387
-
1388
- ## sameDeepMembers
1389
-
1390
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1391
-
1392
- Asserts that `set1` and `set2` have the same members in any order. Uses a deep equality check.
1393
-
1394
- ```ts
1395
- import { assert, test } from 'vitest'
1396
-
1397
- test('assert.sameDeepMembers', () => {
1398
- assert.sameDeepMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { a: 1 }, { c: 3 }], 'same deep members')
1399
- })
1400
- ```
1401
-
1402
- ## notSameDeepMembers
1403
-
1404
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1405
-
1406
- Asserts that `set1` and `set2` don’t have the same members in any order. Uses a deep equality check.
1407
-
1408
- ```ts
1409
- import { assert, test } from 'vitest'
1410
-
1411
- test('assert.sameDeepMembers', () => {
1412
- assert.sameDeepMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { a: 1 }, { c: 3 }], 'same deep members')
1413
- })
1414
- ```
1415
-
1416
- ## sameOrderedMembers
1417
-
1418
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1419
-
1420
- Asserts that `set1` and `set2` have the same members in the same order. Uses a strict equality check (===).
1421
-
1422
- ```ts
1423
- import { assert, test } from 'vitest'
1424
-
1425
- test('assert.sameOrderedMembers', () => {
1426
- assert.sameOrderedMembers([1, 2, 3], [1, 2, 3], 'same ordered members')
1427
- })
1428
- ```
1429
-
1430
- ## notSameOrderedMembers
1431
-
1432
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1433
-
1434
- Asserts that `set1` and `set2` have the same members in the same order. Uses a strict equality check (===).
1435
-
1436
- ```ts
1437
- import { assert, test } from 'vitest'
1438
-
1439
- test('assert.notSameOrderedMembers', () => {
1440
- assert.notSameOrderedMembers([1, 2, 3], [2, 1, 3], 'not same ordered members')
1441
- })
1442
- ```
1443
-
1444
- ## sameDeepOrderedMembers
1445
-
1446
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1447
-
1448
- Asserts that `set1` and `set2` have the same members in the same order. Uses a deep equality check.
1449
-
1450
- ```ts
1451
- import { assert, test } from 'vitest'
1452
-
1453
- test('assert.sameDeepOrderedMembers', () => {
1454
- assert.sameDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ a: 1 }, { b: 2 }, { c: 3 }], 'same deep ordered members')
1455
- })
1456
- ```
1457
-
1458
- ## notSameDeepOrderedMembers
1459
-
1460
- - **Type:** `<T>(set1: T[], set2: T[], message?: string) => void`
1461
-
1462
- Asserts that `set1` and `set2` don’t have the same members in the same order. Uses a deep equality check.
1463
-
1464
- ```ts
1465
- import { assert, test } from 'vitest'
1466
-
1467
- test('assert.notSameDeepOrderedMembers', () => {
1468
- assert.notSameDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ a: 1 }, { b: 2 }, { z: 5 }], 'not same deep ordered members')
1469
- assert.notSameDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { a: 1 }, { c: 3 }], 'not same deep ordered members')
1470
- })
1471
- ```
1472
-
1473
- ## includeMembers
1474
-
1475
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1476
-
1477
- Asserts that `subset` is included in `superset` in any order. Uses a strict equality check (===). Duplicates are ignored.
1478
-
1479
- ```ts
1480
- import { assert, test } from 'vitest'
1481
-
1482
- test('assert.includeMembers', () => {
1483
- assert.includeMembers([1, 2, 3], [2, 1, 2], 'include members')
1484
- })
1485
- ```
1486
-
1487
- ## notIncludeMembers
1488
-
1489
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1490
-
1491
- Asserts that `subset` isn't included in `superset` in any order. Uses a strict equality check (===). Duplicates are ignored.
1492
-
1493
- ```ts
1494
- import { assert, test } from 'vitest'
1495
-
1496
- test('assert.notIncludeMembers', () => {
1497
- assert.notIncludeMembers([1, 2, 3], [5, 1], 'not include members')
1498
- })
1499
- ```
1500
-
1501
- ## includeDeepMembers
1502
-
1503
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1504
-
1505
- Asserts that `subset` is included in `superset` in any order. Uses a deep equality check. Duplicates are ignored.
1506
-
1507
- ```ts
1508
- import { assert, test } from 'vitest'
1509
-
1510
- test('assert.includeDeepMembers', () => {
1511
- assert.includeDeepMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { a: 1 }, { b: 2 }], 'include deep members')
1512
- })
1513
- ```
1514
-
1515
- ## notIncludeDeepMembers
1516
-
1517
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1518
-
1519
- Asserts that `subset` isn’t included in `superset` in any order. Uses a deep equality check. Duplicates are ignored.
1520
-
1521
- ```ts
1522
- import { assert, test } from 'vitest'
1523
-
1524
- test('assert.notIncludeDeepMembers', () => {
1525
- assert.notIncludeDeepMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { f: 5 }], 'not include deep members')
1526
- })
1527
- ```
1528
-
1529
- ## includeOrderedMembers
1530
-
1531
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1532
-
1533
- Asserts that `subset` is included in `superset` in the same order beginning with the first element in `superset`. Uses a strict equality check (===).
1534
-
1535
- ```ts
1536
- import { assert, test } from 'vitest'
1537
-
1538
- test('assert.includeOrderedMembers', () => {
1539
- assert.includeOrderedMembers([1, 2, 3], [1, 2], 'include ordered members')
1540
- })
1541
- ```
1542
-
1543
- ## notIncludeOrderedMembers
1544
-
1545
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1546
-
1547
- Asserts that `subset` isn't included in `superset` in the same order beginning with the first element in `superset`. Uses a strict equality check (===).
1548
-
1549
- ```ts
1550
- import { assert, test } from 'vitest'
1551
-
1552
- test('assert.notIncludeOrderedMembers', () => {
1553
- assert.notIncludeOrderedMembers([1, 2, 3], [2, 1], 'not include ordered members')
1554
- assert.notIncludeOrderedMembers([1, 2, 3], [2, 3], 'not include ordered members')
1555
- })
1556
- ```
1557
-
1558
- ## includeDeepOrderedMembers
1559
-
1560
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1561
-
1562
- Asserts that `subset` is included in `superset` in the same order beginning with the first element in `superset`. Uses a deep equality check.
1563
-
1564
- ```ts
1565
- import { assert, test } from 'vitest'
1566
-
1567
- test('assert.includeDeepOrderedMembers', () => {
1568
- assert.includeDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ a: 1 }, { b: 2 }], 'include deep ordered members')
1569
- })
1570
- ```
1571
-
1572
- ## notIncludeDeepOrderedMembers
1573
-
1574
- - **Type:** `<T>(superset: T[], subset: T[], message?: string) => void`
1575
-
1576
- Asserts that `subset` isn’t included in `superset` in the same order beginning with the first element in superset. Uses a deep equality check.
1577
-
1578
- ```ts
1579
- import { assert, test } from 'vitest'
1580
-
1581
- test('assert.includeDeepOrderedMembers', () => {
1582
- assert.notIncludeDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ a: 1 }, { f: 5 }], 'not include deep ordered members')
1583
- assert.notIncludeDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { a: 1 }], 'not include deep ordered members')
1584
- assert.notIncludeDeepOrderedMembers([{ a: 1 }, { b: 2 }, { c: 3 }], [{ b: 2 }, { c: 3 }], 'not include deep ordered members')
1585
- })
1586
- ```
1587
-
1588
- ## oneOf
1589
-
1590
- - **Type:** `<T>(inList: T, list: T[], message?: string) => void`
1591
-
1592
- Asserts that non-object, non-array value `inList` appears in the flat array `list`.
1593
-
1594
- ```ts
1595
- import { assert, test } from 'vitest'
1596
-
1597
- test('assert.oneOf', () => {
1598
- assert.oneOf(1, [2, 1], 'Not found in list')
1599
- })
1600
- ```
1601
-
1602
- ## changes
1603
-
1604
- - **Type:** `<T>(modifier: Function, object: T, property: string, message?: string) => void`
1605
-
1606
- Asserts that a `modifier` changes the `object` of a `property`.
1607
-
1608
- ```ts
1609
- import { assert, test } from 'vitest'
1610
-
1611
- test('assert.changes', () => {
1612
- const obj = { val: 10 }
1613
- function fn() { obj.val = 22 };
1614
- assert.changes(fn, obj, 'val')
1615
- })
1616
- ```
1617
-
1618
- ## changesBy
1619
-
1620
- - **Type:** `<T>(modifier: Function, object: T, property: string, change: number, message?: string) => void`
1621
-
1622
- Asserts that a `modifier` changes the `object` of a `property` by a `change`.
1623
-
1624
- ```ts
1625
- import { assert, test } from 'vitest'
1626
-
1627
- test('assert.changesBy', () => {
1628
- const obj = { val: 10 }
1629
- function fn() { obj.val += 2 };
1630
- assert.changesBy(fn, obj, 'val', 2)
1631
- })
1632
- ```
1633
-
1634
- ## doesNotChange
1635
-
1636
- - **Type:** `<T>(modifier: Function, object: T, property: string, message?: string) => void`
1637
-
1638
- Asserts that a `modifier` does not changes the `object` of a `property`.
1639
-
1640
- ```ts
1641
- import { assert, test } from 'vitest'
1642
-
1643
- test('assert.doesNotChange', () => {
1644
- const obj = { val: 10 }
1645
- function fn() { obj.val += 2 };
1646
- assert.doesNotChange(fn, obj, 'val', 2)
1647
- })
1648
- ```
1649
-
1650
- ## changesButNotBy
1651
-
1652
- - **Type:** `<T>(modifier: Function, object: T, property: string, change:number, message?: string) => void`
1653
-
1654
- Asserts that a `modifier` does not change the `object` of a `property` or of a `modifier` return value by a `change`.
1655
-
1656
- ```ts
1657
- import { assert, test } from 'vitest'
1658
-
1659
- test('assert.changesButNotBy', () => {
1660
- const obj = { val: 10 }
1661
- function fn() { obj.val += 10 };
1662
- assert.changesButNotBy(fn, obj, 'val', 5)
1663
- })
1664
- ```
1665
-
1666
- ## increases
1667
-
1668
- - **Type:** `<T>(modifier: Function, object: T, property: string, message?: string) => void`
1669
-
1670
- Asserts that a `modifier` increases a numeric `object`'s `property`.
1671
-
1672
- ```ts
1673
- import { assert, test } from 'vitest'
1674
-
1675
- test('assert.increases', () => {
1676
- const obj = { val: 10 }
1677
- function fn() { obj.val = 13 };
1678
- assert.increases(fn, obj, 'val')
1679
- })
1680
- ```
1681
-
1682
- ## increasesBy
1683
-
1684
- - **Type:** `<T>(modifier: Function, object: T, property: string, change: number, message?: string) => void`
1685
-
1686
- Asserts that a `modifier` increases a numeric `object`'s `property` or a `modifier` return value by an `change`.
1687
-
1688
- ```ts
1689
- import { assert, test } from 'vitest'
1690
-
1691
- test('assert.increasesBy', () => {
1692
- const obj = { val: 10 }
1693
- function fn() { obj.val += 10 };
1694
- assert.increasesBy(fn, obj, 'val', 10)
1695
- })
1696
- ```
1697
-
1698
- ## doesNotIncrease
1699
-
1700
- - **Type:** `<T>(modifier: Function, object: T, property: string, message?: string) => void`
1701
-
1702
- Asserts that a `modifier` does not increases a numeric `object`'s `property`.
1703
-
1704
- ```ts
1705
- import { assert, test } from 'vitest'
1706
-
1707
- test('assert.doesNotIncrease', () => {
1708
- const obj = { val: 10 }
1709
- function fn() { obj.val = 8 }
1710
- assert.doesNotIncrease(fn, obj, 'val')
1711
- })
1712
- ```
1713
-
1714
- ## increasesButNotBy
1715
-
1716
- - **Type:** `<T>(modifier: Function, object: T, property: string, change: number, message?: string) => void`
1717
-
1718
- Asserts that a `modifier` does not increases a numeric `object`'s `property` or a `modifier` return value by an `change`.
1719
-
1720
- ```ts
1721
- import { assert, test } from 'vitest'
1722
-
1723
- test('assert.increasesButNotBy', () => {
1724
- const obj = { val: 10 }
1725
- function fn() { obj.val += 15 };
1726
- assert.increasesButNotBy(fn, obj, 'val', 10)
1727
- })
1728
- ```
1729
-
1730
- ## decreases
1731
-
1732
- - **Type:** `<T>(modifier: Function, object: T, property: string, message?: string) => void`
1733
-
1734
- Asserts that a `modifier` decreases a numeric `object`'s `property`.
1735
-
1736
- ```ts
1737
- import { assert, test } from 'vitest'
1738
-
1739
- test('assert.decreases', () => {
1740
- const obj = { val: 10 }
1741
- function fn() { obj.val = 5 };
1742
- assert.decreases(fn, obj, 'val')
1743
- })
1744
- ```
1745
-
1746
- ## decreasesBy
1747
-
1748
- - **Type:** `<T>(modifier: Function, object: T, property: string, change: number, message?: string) => void`
1749
-
1750
- Asserts that a `modifier` decreases a numeric `object`'s `property` or a `modifier` return value by a `change`.
1751
-
1752
- ```ts
1753
- import { assert, test } from 'vitest'
1754
-
1755
- test('assert.decreasesBy', () => {
1756
- const obj = { val: 10 }
1757
- function fn() { obj.val -= 5 };
1758
- assert.decreasesBy(fn, obj, 'val', 5)
1759
- })
1760
- ```
1761
-
1762
- ## doesNotDecrease
1763
-
1764
- - **Type:** `<T>(modifier: Function, object: T, property: string, message?: string) => void`
1765
-
1766
- Asserts that a `modifier` dose not decrease a numeric `object`'s `property`.
1767
-
1768
- ```ts
1769
- import { assert, test } from 'vitest'
1770
-
1771
- test('assert.doesNotDecrease', () => {
1772
- const obj = { val: 10 }
1773
- function fn() { obj.val = 15 }
1774
- assert.doesNotDecrease(fn, obj, 'val')
1775
- })
1776
- ```
1777
-
1778
- ## doesNotDecreaseBy
1779
-
1780
- - **Type:** `<T>(modifier: Function, object: T, property: string, change: number, message?: string) => void`
1781
-
1782
- Asserts that a `modifier` does not decrease a numeric `object`'s `property` or a `modifier` return value by a `change`.
1783
-
1784
- ```ts
1785
- import { assert, test } from 'vitest'
1786
-
1787
- test('assert.doesNotDecreaseBy', () => {
1788
- const obj = { val: 10 }
1789
- function fn() { obj.val = 5 };
1790
- assert.doesNotDecreaseBy(fn, obj, 'val', 1)
1791
- })
1792
- ```
1793
-
1794
- ## decreasesButNotBy
1795
-
1796
- - **Type:** `<T>(modifier: Function, object: T, property: string, change: number, message?: string) => void`
1797
-
1798
- Asserts that a `modifier` does not decrease a numeric `object`'s `property` or a `modifier` return value by a `change`.
1799
-
1800
- ```ts
1801
- import { assert, test } from 'vitest'
1802
-
1803
- test('assert.decreasesButNotBy', () => {
1804
- const obj = { val: 10 }
1805
- function fn() { obj.val = 5 };
1806
- assert.decreasesButNotBy(fn, obj, 'val', 1)
1807
- })
1808
- ```
1809
-
1810
- ## ifError
1811
-
1812
- - **Type:** `<T>(object: T, message?: string) => void`
1813
-
1814
- Asserts if `object` is not a false value, and throws if it is a true value. This is added to allow for chai to be a drop-in replacement for Node’s assert class.
1815
-
1816
- ```ts
1817
- import { assert, test } from 'vitest'
1818
-
1819
- test('assert.ifError', () => {
1820
- const err = new Error('I am a custom error')
1821
- assert.ifError(err) // Rethrows err!
1822
- })
1823
- ```
1824
-
1825
- ## isExtensible
1826
-
1827
- - **Type:** `<T>(object: T, message?: string) => void`
1828
- - **Alias:** `extensible`
1829
-
1830
- Asserts that `object` is extensible (can have new properties added to it).
1831
-
1832
- ```ts
1833
- import { assert, test } from 'vitest'
1834
-
1835
- test('assert.isExtensible', () => {
1836
- assert.isExtensible({})
1837
- })
1838
- ```
1839
-
1840
- ## isNotExtensible
1841
-
1842
- - **Type:** `<T>(object: T, message?: string) => void`
1843
- - **Alias:** `notExtensible`
1844
-
1845
- Asserts that `object` is not extensible (can not have new properties added to it).
1846
-
1847
- ```ts
1848
- import { assert, test } from 'vitest'
1849
-
1850
- test('assert.isNotExtensible', () => {
1851
- const nonExtensibleObject = Object.preventExtensions({})
1852
- const sealedObject = Object.seal({})
1853
- const frozenObject = Object.freeze({})
1854
-
1855
- assert.isNotExtensible(nonExtensibleObject)
1856
- assert.isNotExtensible(sealedObject)
1857
- assert.isNotExtensible(frozenObject)
1858
- })
1859
- ```
1860
-
1861
- ## isSealed
1862
-
1863
- - **Type:** `<T>(object: T, message?: string) => void`
1864
- - **Alias:** `sealed`
1865
-
1866
- Asserts that `object` is sealed (cannot have new properties added to it and its existing properties cannot be removed).
1867
-
1868
- ```ts
1869
- import { assert, test } from 'vitest'
1870
-
1871
- test('assert.isSealed', () => {
1872
- const sealedObject = Object.seal({})
1873
- const frozenObject = Object.seal({})
1874
-
1875
- assert.isSealed(sealedObject)
1876
- assert.isSealed(frozenObject)
1877
- })
1878
- ```
1879
-
1880
- ## isNotSealed
1881
-
1882
- - **Type:** `<T>(object: T, message?: string) => void`
1883
- - **Alias:** `notSealed`
1884
-
1885
- Asserts that `object` is not sealed (can have new properties added to it and its existing properties can be removed).
1886
-
1887
- ```ts
1888
- import { assert, test } from 'vitest'
1889
-
1890
- test('assert.isNotSealed', () => {
1891
- assert.isNotSealed({})
1892
- })
1893
- ```
1894
-
1895
- ## isFrozen
1896
-
1897
- - **Type:** `<T>(object: T, message?: string) => void`
1898
- - **Alias:** `frozen`
1899
-
1900
- Asserts that object is frozen (cannot have new properties added to it and its existing properties cannot be modified).
1901
-
1902
- ```ts
1903
- import { assert, test } from 'vitest'
1904
-
1905
- test('assert.isFrozen', () => {
1906
- const frozenObject = Object.freeze({})
1907
- assert.frozen(frozenObject)
1908
- })
1909
- ```
1910
-
1911
- ## isNotFrozen
1912
-
1913
- - **Type:** `<T>(object: T, message?: string) => void`
1914
- - **Alias:** `notFrozen`
1915
-
1916
- Asserts that `object` is not frozen (can have new properties added to it and its existing properties can be modified).
1917
-
1918
- ```ts
1919
- import { assert, test } from 'vitest'
1920
-
1921
- test('assert.isNotFrozen', () => {
1922
- assert.isNotFrozen({})
1923
- })
1924
- ```
1925
-
1926
- ## isEmpty
1927
-
1928
- - **Type:** `<T>(target: T, message?: string) => void`
1929
- - **Alias:** `empty`
1930
-
1931
- Asserts that the `target` does not contain any values. For arrays and strings, it checks the length property. For Map and Set instances, it checks the size property. For non-function objects, it gets the count of its own enumerable string keys.
1932
-
1933
- ```ts
1934
- import { assert, test } from 'vitest'
1935
-
1936
- test('assert.isEmpty', () => {
1937
- assert.isEmpty([])
1938
- assert.isEmpty('')
1939
- assert.isEmpty(new Map())
1940
- assert.isEmpty({})
1941
- })
1942
- ```
1943
-
1944
- ## isNotEmpty
1945
-
1946
- - **Type:** `<T>(object: T, message?: string) => void`
1947
- - **Alias:** `notEmpty`
1948
-
1949
- Asserts that the `target` contains values. For arrays and strings, it checks the length property. For Map and Set instances, it checks the size property. For non-function objects, it gets the count of its own enumerable string keys.
1950
-
1951
- ```ts
1952
- import { assert, test } from 'vitest'
1953
-
1954
- test('assert.isNotEmpty', () => {
1955
- assert.isNotEmpty([1, 2])
1956
- assert.isNotEmpty('34')
1957
- assert.isNotEmpty(new Set([5, 6]))
1958
- assert.isNotEmpty({ key: 7 })
1959
- })
1960
- ```