@effect/vitest 4.0.0-beta.9 → 4.0.0-beta.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  /**
2
+ * Provides assertion helpers used by `@effect/vitest` tests.
3
+ *
4
+ * This module defines small assertion functions built on Node's `assert`,
5
+ * Vitest's instance checks, and Effect's equality support. The helpers cover
6
+ * basic equality, thrown errors, defined and undefined values, strings, regular
7
+ * expressions, class instances, `Option`, `Result`, and `Exit`. Most helpers are
8
+ * synchronous; `throwsAsync` handles rejected promises.
9
+ *
2
10
  * @since 4.0.0
3
11
  */
4
12
  import type * as Cause from "effect/Cause"
@@ -15,8 +23,9 @@ import { assert as vassert } from "vitest"
15
23
  // ----------------------------
16
24
 
17
25
  /**
18
- * Throws an `AssertionError` with the provided error message.
26
+ * Fails the current test with the provided error message.
19
27
  *
28
+ * @category testing
20
29
  * @since 4.0.0
21
30
  */
22
31
  export function fail(message: string) {
@@ -24,8 +33,9 @@ export function fail(message: string) {
24
33
  }
25
34
 
26
35
  /**
27
- * Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
36
+ * Asserts that `actual` is deeply strictly equal to `expected` using Node's `assert.deepStrictEqual`.
28
37
  *
38
+ * @category testing
29
39
  * @since 4.0.0
30
40
  */
31
41
  export function deepStrictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
@@ -33,8 +43,9 @@ export function deepStrictEqual<A>(actual: A, expected: A, message?: string, ...
33
43
  }
34
44
 
35
45
  /**
36
- * Asserts that `actual` is not equal to `expected` using the `Equal.equals` trait.
46
+ * Asserts that `actual` is not deeply strictly equal to `expected` using Node's `assert.notDeepStrictEqual`.
37
47
  *
48
+ * @category testing
38
49
  * @since 4.0.0
39
50
  */
40
51
  export function notDeepStrictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
@@ -42,8 +53,9 @@ export function notDeepStrictEqual<A>(actual: A, expected: A, message?: string,
42
53
  }
43
54
 
44
55
  /**
45
- * Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
56
+ * Asserts that `actual` is strictly equal to `expected` using Node's `assert.strictEqual`.
46
57
  *
58
+ * @category testing
47
59
  * @since 4.0.0
48
60
  */
49
61
  export function strictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
@@ -53,6 +65,7 @@ export function strictEqual<A>(actual: A, expected: A, message?: string, ..._: A
53
65
  /**
54
66
  * Asserts that `actual` is equal to `expected` using the `Equal.equals` trait.
55
67
  *
68
+ * @category testing
56
69
  * @since 4.0.0
57
70
  */
58
71
  export function assertEquals<A>(actual: A, expected: A, message?: string, ..._: Array<never>) {
@@ -65,6 +78,7 @@ export function assertEquals<A>(actual: A, expected: A, message?: string, ..._:
65
78
  /**
66
79
  * Asserts that `thunk` does not throw an error.
67
80
  *
81
+ * @category testing
68
82
  * @since 4.0.0
69
83
  */
70
84
  export function doesNotThrow(thunk: () => void, message?: string, ..._: Array<never>) {
@@ -78,6 +92,7 @@ export function doesNotThrow(thunk: () => void, message?: string, ..._: Array<ne
78
92
  /**
79
93
  * Asserts that `value` is an instance of `constructor`.
80
94
  *
95
+ * @category testing
81
96
  * @since 4.0.0
82
97
  */
83
98
  export function assertInstanceOf<C extends abstract new(...args: any) => any>(
@@ -92,6 +107,7 @@ export function assertInstanceOf<C extends abstract new(...args: any) => any>(
92
107
  /**
93
108
  * Asserts that `self` is `true`.
94
109
  *
110
+ * @category testing
95
111
  * @since 4.0.0
96
112
  */
97
113
  export function assertTrue(self: unknown, message?: string, ..._: Array<never>): asserts self {
@@ -101,6 +117,7 @@ export function assertTrue(self: unknown, message?: string, ..._: Array<never>):
101
117
  /**
102
118
  * Asserts that `self` is `false`.
103
119
  *
120
+ * @category testing
104
121
  * @since 4.0.0
105
122
  */
106
123
  export function assertFalse(self: boolean, message?: string, ..._: Array<never>) {
@@ -110,6 +127,7 @@ export function assertFalse(self: boolean, message?: string, ..._: Array<never>)
110
127
  /**
111
128
  * Asserts that `actual` includes `expected`.
112
129
  *
130
+ * @category testing
113
131
  * @since 4.0.0
114
132
  */
115
133
  export function assertInclude(actual: string | undefined, expected: string, ..._: Array<never>) {
@@ -123,6 +141,7 @@ export function assertInclude(actual: string | undefined, expected: string, ..._
123
141
  /**
124
142
  * Asserts that `actual` matches `regExp`.
125
143
  *
144
+ * @category testing
126
145
  * @since 4.0.0
127
146
  */
128
147
  export function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>) {
@@ -132,8 +151,9 @@ export function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>)
132
151
  }
133
152
 
134
153
  /**
135
- * Asserts that `thunk` throws an error.
154
+ * Asserts that `thunk` throws, optionally checking the thrown value against an expected `Error` or validation function.
136
155
  *
156
+ * @category testing
137
157
  * @since 4.0.0
138
158
  */
139
159
  export function throws(thunk: () => void, error?: Error | ((u: unknown) => undefined), ..._: Array<never>) {
@@ -154,8 +174,9 @@ export function throws(thunk: () => void, error?: Error | ((u: unknown) => undef
154
174
  }
155
175
 
156
176
  /**
157
- * Asserts that `thunk` throws an error.
177
+ * Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an expected `Error` or validation function.
158
178
  *
179
+ * @category testing
159
180
  * @since 4.0.0
160
181
  */
161
182
  export async function throwsAsync(
@@ -184,6 +205,7 @@ export async function throwsAsync(
184
205
  /**
185
206
  * Asserts that `option` is `None`.
186
207
  *
208
+ * @category testing
187
209
  * @since 4.0.0
188
210
  */
189
211
  export function assertNone<A>(option: Option.Option<A>, ..._: Array<never>): asserts option is Option.None<never> {
@@ -193,6 +215,7 @@ export function assertNone<A>(option: Option.Option<A>, ..._: Array<never>): ass
193
215
  /**
194
216
  * Asserts that `a` is not `undefined`.
195
217
  *
218
+ * @category testing
196
219
  * @since 4.0.0
197
220
  */
198
221
  export function assertDefined<A>(
@@ -207,6 +230,7 @@ export function assertDefined<A>(
207
230
  /**
208
231
  * Asserts that `a` is `undefined`.
209
232
  *
233
+ * @category testing
210
234
  * @since 4.0.0
211
235
  */
212
236
  export function assertUndefined<A>(
@@ -219,8 +243,9 @@ export function assertUndefined<A>(
219
243
  }
220
244
 
221
245
  /**
222
- * Asserts that `option` is `Some`.
246
+ * Asserts that `option` is `Some` and contains a value equal to `expected`.
223
247
  *
248
+ * @category testing
224
249
  * @since 4.0.0
225
250
  */
226
251
  export function assertSome<A>(
@@ -236,8 +261,9 @@ export function assertSome<A>(
236
261
  // ----------------------------
237
262
 
238
263
  /**
239
- * Asserts that `result` is `Success`.
264
+ * Asserts that `result` is `Success` and contains a value equal to `expected`.
240
265
  *
266
+ * @category testing
241
267
  * @since 4.0.0
242
268
  */
243
269
  export function assertSuccess<A, E>(
@@ -249,8 +275,9 @@ export function assertSuccess<A, E>(
249
275
  }
250
276
 
251
277
  /**
252
- * Asserts that `result` is `Failure`.
278
+ * Asserts that `result` is `Failure` and contains an error equal to `expected`.
253
279
  *
280
+ * @category testing
254
281
  * @since 4.0.0
255
282
  */
256
283
  export function assertFailure<A, E>(
@@ -266,8 +293,9 @@ export function assertFailure<A, E>(
266
293
  // ----------------------------
267
294
 
268
295
  /**
269
- * Asserts that `exit` is a failure.
296
+ * Asserts that `exit` is a failure with a cause equal to `expected`.
270
297
  *
298
+ * @category testing
271
299
  * @since 4.0.0
272
300
  */
273
301
  export function assertExitFailure<A, E>(
@@ -279,8 +307,9 @@ export function assertExitFailure<A, E>(
279
307
  }
280
308
 
281
309
  /**
282
- * Asserts that `exit` is a success.
310
+ * Asserts that `exit` is a success with a value equal to `expected`.
283
311
  *
312
+ * @category testing
284
313
  * @since 4.0.0
285
314
  */
286
315
  export function assertExitSuccess<A, E>(