@kerebron/test-utils 0.4.27 → 0.4.29

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 (182) hide show
  1. package/esm/_dnt.shims.d.ts +2 -0
  2. package/esm/_dnt.shims.d.ts.map +1 -0
  3. package/esm/_dnt.shims.js +58 -0
  4. package/esm/_dnt.shims.js.map +1 -0
  5. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +29 -0
  6. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
  7. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +47 -0
  8. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.js.map +1 -0
  9. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +24 -0
  10. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.js +47 -0
  12. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.js.map +1 -0
  13. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +16 -0
  14. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.js +23 -0
  16. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.js.map +1 -0
  17. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +26 -0
  18. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +31 -0
  20. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js.map +1 -0
  21. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +17 -0
  22. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.js +187 -0
  24. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.js.map +1 -0
  25. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +35 -0
  26. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.js +60 -0
  28. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.js.map +1 -0
  29. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +18 -0
  30. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.js +28 -0
  32. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.js.map +1 -0
  33. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +15 -0
  34. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.js +21 -0
  36. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.js.map +1 -0
  37. package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts +18 -0
  38. package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@std/assert/1.0.16/false.js +23 -0
  40. package/esm/deps/jsr.io/@std/assert/1.0.16/false.js.map +1 -0
  41. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +20 -0
  42. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
  43. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.js +30 -0
  44. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.js.map +1 -0
  45. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +20 -0
  46. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +30 -0
  48. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js.map +1 -0
  49. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +23 -0
  50. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js +53 -0
  52. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js.map +1 -0
  53. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +25 -0
  54. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
  55. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.js +54 -0
  56. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.js.map +1 -0
  57. package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts +19 -0
  58. package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
  59. package/esm/deps/jsr.io/@std/assert/1.0.16/less.js +29 -0
  60. package/esm/deps/jsr.io/@std/assert/1.0.16/less.js.map +1 -0
  61. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +20 -0
  62. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +30 -0
  64. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js.map +1 -0
  65. package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts +18 -0
  66. package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
  67. package/esm/deps/jsr.io/@std/assert/1.0.16/match.js +27 -0
  68. package/esm/deps/jsr.io/@std/assert/1.0.16/match.js.map +1 -0
  69. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +44 -0
  70. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
  71. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.js +46 -0
  72. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.js.map +1 -0
  73. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +21 -0
  74. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.js +34 -0
  76. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.js.map +1 -0
  77. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +20 -0
  78. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
  79. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +30 -0
  80. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js.map +1 -0
  81. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +18 -0
  82. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
  83. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.js +27 -0
  84. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.js.map +1 -0
  85. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +23 -0
  86. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
  87. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +33 -0
  88. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js.map +1 -0
  89. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +29 -0
  90. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
  91. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.js +168 -0
  92. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.js.map +1 -0
  93. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +42 -0
  94. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
  95. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.js +54 -0
  96. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.js.map +1 -0
  97. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +24 -0
  98. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
  99. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +59 -0
  100. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.js.map +1 -0
  101. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +18 -0
  102. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
  103. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.js +27 -0
  104. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.js.map +1 -0
  105. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +45 -0
  106. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
  107. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.js +45 -0
  108. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.js.map +1 -0
  109. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +15 -0
  110. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
  111. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +21 -0
  112. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.js.map +1 -0
  113. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +15 -0
  114. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
  115. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.js +21 -0
  116. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.js.map +1 -0
  117. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +80 -0
  118. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
  119. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.js +117 -0
  120. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.js.map +1 -0
  121. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +140 -0
  122. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
  123. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.js +277 -0
  124. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.js.map +1 -0
  125. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +99 -0
  126. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
  127. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.js +183 -0
  128. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.js.map +1 -0
  129. package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts +29 -0
  130. package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
  131. package/esm/deps/jsr.io/@std/internal/1.0.12/format.js +71 -0
  132. package/esm/deps/jsr.io/@std/internal/1.0.12/format.js.map +1 -0
  133. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +159 -0
  134. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
  135. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.js +208 -0
  136. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.js.map +1 -0
  137. package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts +25 -0
  138. package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
  139. package/esm/deps/jsr.io/@std/internal/1.0.12/types.js +4 -0
  140. package/esm/deps/jsr.io/@std/internal/1.0.12/types.js.map +1 -0
  141. package/esm/package.json +3 -0
  142. package/esm/test-utils.d.ts +3 -0
  143. package/esm/test-utils.d.ts.map +1 -0
  144. package/esm/test-utils.js +12 -0
  145. package/esm/test-utils.js.map +1 -0
  146. package/package.json +5 -2
  147. package/src/_dnt.shims.ts +60 -0
  148. package/src/deps/jsr.io/@std/assert/1.0.16/almost_equals.ts +55 -0
  149. package/src/deps/jsr.io/@std/assert/1.0.16/array_includes.ts +57 -0
  150. package/src/deps/jsr.io/@std/assert/1.0.16/assert.ts +23 -0
  151. package/src/deps/jsr.io/@std/assert/1.0.16/assertion_error.ts +31 -0
  152. package/src/deps/jsr.io/@std/assert/1.0.16/equal.ts +218 -0
  153. package/src/deps/jsr.io/@std/assert/1.0.16/equals.ts +66 -0
  154. package/src/deps/jsr.io/@std/assert/1.0.16/exists.ts +31 -0
  155. package/src/deps/jsr.io/@std/assert/1.0.16/fail.ts +21 -0
  156. package/src/deps/jsr.io/@std/assert/1.0.16/false.ts +26 -0
  157. package/src/deps/jsr.io/@std/assert/1.0.16/greater.ts +30 -0
  158. package/src/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.ts +36 -0
  159. package/src/deps/jsr.io/@std/assert/1.0.16/instance_of.ts +64 -0
  160. package/src/deps/jsr.io/@std/assert/1.0.16/is_error.ts +65 -0
  161. package/src/deps/jsr.io/@std/assert/1.0.16/less.ts +29 -0
  162. package/src/deps/jsr.io/@std/assert/1.0.16/less_or_equal.ts +36 -0
  163. package/src/deps/jsr.io/@std/assert/1.0.16/match.ts +30 -0
  164. package/src/deps/jsr.io/@std/assert/1.0.16/mod.ts +47 -0
  165. package/src/deps/jsr.io/@std/assert/1.0.16/not_equals.ts +37 -0
  166. package/src/deps/jsr.io/@std/assert/1.0.16/not_instance_of.ts +33 -0
  167. package/src/deps/jsr.io/@std/assert/1.0.16/not_match.ts +30 -0
  168. package/src/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.ts +42 -0
  169. package/src/deps/jsr.io/@std/assert/1.0.16/object_match.ts +214 -0
  170. package/src/deps/jsr.io/@std/assert/1.0.16/rejects.ts +123 -0
  171. package/src/deps/jsr.io/@std/assert/1.0.16/strict_equals.ts +68 -0
  172. package/src/deps/jsr.io/@std/assert/1.0.16/string_includes.ts +30 -0
  173. package/src/deps/jsr.io/@std/assert/1.0.16/throws.ts +111 -0
  174. package/src/deps/jsr.io/@std/assert/1.0.16/unimplemented.ts +21 -0
  175. package/src/deps/jsr.io/@std/assert/1.0.16/unreachable.ts +21 -0
  176. package/src/deps/jsr.io/@std/internal/1.0.12/build_message.ts +147 -0
  177. package/src/deps/jsr.io/@std/internal/1.0.12/diff.ts +317 -0
  178. package/src/deps/jsr.io/@std/internal/1.0.12/diff_str.ts +208 -0
  179. package/src/deps/jsr.io/@std/internal/1.0.12/format.ts +89 -0
  180. package/src/deps/jsr.io/@std/internal/1.0.12/styles.ts +233 -0
  181. package/src/deps/jsr.io/@std/internal/1.0.12/types.ts +30 -0
  182. package/src/test-utils.ts +12 -0
@@ -0,0 +1,30 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { format } from "../../internal/1.0.12/format.js";
4
+ import { AssertionError } from "./assertion_error.js";
5
+
6
+ /**
7
+ * Make an assertion that `actual` is greater than `expected`.
8
+ * If not then throw.
9
+ *
10
+ * @example Usage
11
+ * ```ts ignore
12
+ * import { assertGreater } from "@std/assert";
13
+ *
14
+ * assertGreater(2, 1); // Doesn't throw
15
+ * assertGreater(1, 1); // Throws
16
+ * assertGreater(0, 1); // Throws
17
+ * ```
18
+ *
19
+ * @typeParam T The type of the values to compare.
20
+ * @param actual The actual value to compare.
21
+ * @param expected The expected value to compare.
22
+ * @param msg The optional message to display if the assertion fails.
23
+ */
24
+ export function assertGreater<T>(actual: T, expected: T, msg?: string) {
25
+ if (actual > expected) return;
26
+
27
+ const actualString = format(actual);
28
+ const expectedString = format(expected);
29
+ throw new AssertionError(msg ?? `Expect ${actualString} > ${expectedString}`);
30
+ }
@@ -0,0 +1,36 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { format } from "../../internal/1.0.12/format.js";
4
+ import { AssertionError } from "./assertion_error.js";
5
+
6
+ /**
7
+ * Make an assertion that `actual` is greater than or equal to `expected`.
8
+ * If not then throw.
9
+ *
10
+ * @example Usage
11
+ * ```ts ignore
12
+ * import { assertGreaterOrEqual } from "@std/assert";
13
+ *
14
+ * assertGreaterOrEqual(2, 1); // Doesn't throw
15
+ * assertGreaterOrEqual(1, 1); // Doesn't throw
16
+ * assertGreaterOrEqual(0, 1); // Throws
17
+ * ```
18
+ *
19
+ * @typeParam T The type of the values to compare.
20
+ * @param actual The actual value to compare.
21
+ * @param expected The expected value to compare.
22
+ * @param msg The optional message to display if the assertion fails.
23
+ */
24
+ export function assertGreaterOrEqual<T>(
25
+ actual: T,
26
+ expected: T,
27
+ msg?: string,
28
+ ) {
29
+ if (actual >= expected) return;
30
+
31
+ const actualString = format(actual);
32
+ const expectedString = format(expected);
33
+ throw new AssertionError(
34
+ msg ?? `Expect ${actualString} >= ${expectedString}`,
35
+ );
36
+ }
@@ -0,0 +1,64 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { AssertionError } from "./assertion_error.js";
4
+
5
+ /** Any constructor */
6
+ // deno-lint-ignore no-explicit-any
7
+ export type AnyConstructor = new (...args: any[]) => any;
8
+ /** Gets constructor type */
9
+ export type GetConstructorType<T extends AnyConstructor> = InstanceType<T>;
10
+
11
+ /**
12
+ * Make an assertion that `obj` is an instance of `type`.
13
+ * If not then throw.
14
+ *
15
+ * @example Usage
16
+ * ```ts ignore
17
+ * import { assertInstanceOf } from "@std/assert";
18
+ *
19
+ * assertInstanceOf(new Date(), Date); // Doesn't throw
20
+ * assertInstanceOf(new Date(), Number); // Throws
21
+ * ```
22
+ *
23
+ * @typeParam T The expected type of the object.
24
+ * @param actual The object to check.
25
+ * @param expectedType The expected class constructor.
26
+ * @param msg The optional message to display if the assertion fails.
27
+ */
28
+ export function assertInstanceOf<
29
+ // deno-lint-ignore no-explicit-any
30
+ T extends abstract new (...args: any[]) => any,
31
+ >(
32
+ actual: unknown,
33
+ expectedType: T,
34
+ msg = "",
35
+ ): asserts actual is InstanceType<T> {
36
+ if (actual instanceof expectedType) return;
37
+
38
+ const msgSuffix = msg ? `: ${msg}` : ".";
39
+ const expectedTypeStr = expectedType.name;
40
+
41
+ let actualTypeStr = "";
42
+ if (actual === null) {
43
+ actualTypeStr = "null";
44
+ } else if (actual === undefined) {
45
+ actualTypeStr = "undefined";
46
+ } else if (typeof actual === "object") {
47
+ actualTypeStr = actual.constructor?.name ?? "Object";
48
+ } else {
49
+ actualTypeStr = typeof actual;
50
+ }
51
+
52
+ if (expectedTypeStr === actualTypeStr) {
53
+ msg =
54
+ `Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`;
55
+ } else if (actualTypeStr === "function") {
56
+ msg =
57
+ `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`;
58
+ } else {
59
+ msg =
60
+ `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}"${msgSuffix}`;
61
+ }
62
+
63
+ throw new AssertionError(msg);
64
+ }
@@ -0,0 +1,65 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { AssertionError } from "./assertion_error.js";
4
+ import { stripAnsiCode } from "../../internal/1.0.12/styles.js";
5
+
6
+ /**
7
+ * Make an assertion that `error` is an `Error`.
8
+ * If not then an error will be thrown.
9
+ * An error class and a string that should be included in the
10
+ * error message can also be asserted.
11
+ *
12
+ * @example Usage
13
+ * ```ts ignore
14
+ * import { assertIsError } from "@std/assert";
15
+ *
16
+ * assertIsError(null); // Throws
17
+ * assertIsError(new RangeError("Out of range")); // Doesn't throw
18
+ * assertIsError(new RangeError("Out of range"), SyntaxError); // Throws
19
+ * assertIsError(new RangeError("Out of range"), SyntaxError, "Out of range"); // Doesn't throw
20
+ * assertIsError(new RangeError("Out of range"), SyntaxError, "Within range"); // Throws
21
+ * ```
22
+ *
23
+ * @typeParam E The type of the error to assert.
24
+ * @param error The error to assert.
25
+ * @param ErrorClass The optional error class to assert.
26
+ * @param msgMatches The optional string or RegExp to assert in the error message.
27
+ * @param msg The optional message to display if the assertion fails.
28
+ */
29
+ export function assertIsError<E extends Error = Error>(
30
+ error: unknown,
31
+ // deno-lint-ignore no-explicit-any
32
+ ErrorClass?: abstract new (...args: any[]) => E,
33
+ msgMatches?: string | RegExp,
34
+ msg?: string,
35
+ ): asserts error is E {
36
+ const msgSuffix = msg ? `: ${msg}` : ".";
37
+ if (!(error instanceof Error)) {
38
+ throw new AssertionError(
39
+ `Expected "error" to be an Error object${msgSuffix}`,
40
+ );
41
+ }
42
+ if (ErrorClass && !(error instanceof ErrorClass)) {
43
+ msg =
44
+ `Expected error to be instance of "${ErrorClass.name}", but was "${error?.constructor?.name}"${msgSuffix}`;
45
+ throw new AssertionError(msg);
46
+ }
47
+ let msgCheck;
48
+ if (typeof msgMatches === "string") {
49
+ msgCheck = stripAnsiCode(error.message).includes(
50
+ stripAnsiCode(msgMatches),
51
+ );
52
+ }
53
+ if (msgMatches instanceof RegExp) {
54
+ msgCheck = msgMatches.test(stripAnsiCode(error.message));
55
+ }
56
+
57
+ if (msgMatches && !msgCheck) {
58
+ msg = `Expected error message to include ${
59
+ msgMatches instanceof RegExp
60
+ ? msgMatches.toString()
61
+ : JSON.stringify(msgMatches)
62
+ }, but got ${JSON.stringify(error?.message)}${msgSuffix}`;
63
+ throw new AssertionError(msg);
64
+ }
65
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { format } from "../../internal/1.0.12/format.js";
4
+ import { AssertionError } from "./assertion_error.js";
5
+
6
+ /**
7
+ * Make an assertion that `actual` is less than `expected`.
8
+ * If not then throw.
9
+ *
10
+ * @example Usage
11
+ * ```ts ignore
12
+ * import { assertLess } from "@std/assert";
13
+ *
14
+ * assertLess(1, 2); // Doesn't throw
15
+ * assertLess(2, 1); // Throws
16
+ * ```
17
+ *
18
+ * @typeParam T The type of the values to compare.
19
+ * @param actual The actual value to compare.
20
+ * @param expected The expected value to compare.
21
+ * @param msg The optional message to display if the assertion fails.
22
+ */
23
+ export function assertLess<T>(actual: T, expected: T, msg?: string) {
24
+ if (actual < expected) return;
25
+
26
+ const actualString = format(actual);
27
+ const expectedString = format(expected);
28
+ throw new AssertionError(msg ?? `Expect ${actualString} < ${expectedString}`);
29
+ }
@@ -0,0 +1,36 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { format } from "../../internal/1.0.12/format.js";
4
+ import { AssertionError } from "./assertion_error.js";
5
+
6
+ /**
7
+ * Make an assertion that `actual` is less than or equal to `expected`.
8
+ * If not then throw.
9
+ *
10
+ * @example Usage
11
+ * ```ts ignore
12
+ * import { assertLessOrEqual } from "@std/assert";
13
+ *
14
+ * assertLessOrEqual(1, 2); // Doesn't throw
15
+ * assertLessOrEqual(1, 1); // Doesn't throw
16
+ * assertLessOrEqual(1, 0); // Throws
17
+ * ```
18
+ *
19
+ * @typeParam T The type of the values to compare.
20
+ * @param actual The actual value to compare.
21
+ * @param expected The expected value to compare.
22
+ * @param msg The optional message to display if the assertion fails.
23
+ */
24
+ export function assertLessOrEqual<T>(
25
+ actual: T,
26
+ expected: T,
27
+ msg?: string,
28
+ ) {
29
+ if (actual <= expected) return;
30
+
31
+ const actualString = format(actual);
32
+ const expectedString = format(expected);
33
+ throw new AssertionError(
34
+ msg ?? `Expect ${actualString} <= ${expectedString}`,
35
+ );
36
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { AssertionError } from "./assertion_error.js";
4
+
5
+ /**
6
+ * Make an assertion that `actual` match RegExp `expected`. If not
7
+ * then throw.
8
+ *
9
+ * @example Usage
10
+ * ```ts ignore
11
+ * import { assertMatch } from "@std/assert";
12
+ *
13
+ * assertMatch("Raptor", /Raptor/); // Doesn't throw
14
+ * assertMatch("Denosaurus", /Raptor/); // Throws
15
+ * ```
16
+ *
17
+ * @param actual The actual value to be matched.
18
+ * @param expected The expected pattern to match.
19
+ * @param msg The optional message to display if the assertion fails.
20
+ */
21
+ export function assertMatch(
22
+ actual: string,
23
+ expected: RegExp,
24
+ msg?: string,
25
+ ) {
26
+ if (expected.test(actual)) return;
27
+ const msgSuffix = msg ? `: ${msg}` : ".";
28
+ msg = `Expected actual: "${actual}" to match: "${expected}"${msgSuffix}`;
29
+ throw new AssertionError(msg);
30
+ }
@@ -0,0 +1,47 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ /** A library of assertion functions.
5
+ * If the assertion is false an `AssertionError` will be thrown which will
6
+ * result in pretty-printed diff of the failing assertion.
7
+ *
8
+ * This module is browser compatible, but do not rely on good formatting of
9
+ * values for AssertionError messages in browsers.
10
+ *
11
+ * ```ts ignore
12
+ * import { assert } from "@std/assert";
13
+ *
14
+ * assert("I am truthy"); // Doesn't throw
15
+ * assert(false); // Throws `AssertionError`
16
+ * ```
17
+ *
18
+ * @module
19
+ */
20
+
21
+ export * from "./almost_equals.js";
22
+ export * from "./array_includes.js";
23
+ export * from "./equals.js";
24
+ export * from "./exists.js";
25
+ export * from "./false.js";
26
+ export * from "./greater_or_equal.js";
27
+ export * from "./greater.js";
28
+ export * from "./instance_of.js";
29
+ export * from "./is_error.js";
30
+ export * from "./less_or_equal.js";
31
+ export * from "./less.js";
32
+ export * from "./match.js";
33
+ export * from "./not_equals.js";
34
+ export * from "./not_instance_of.js";
35
+ export * from "./not_match.js";
36
+ export * from "./not_strict_equals.js";
37
+ export * from "./object_match.js";
38
+ export * from "./rejects.js";
39
+ export * from "./strict_equals.js";
40
+ export * from "./string_includes.js";
41
+ export * from "./throws.js";
42
+ export * from "./assert.js";
43
+ export * from "./assertion_error.js";
44
+ export * from "./equal.js";
45
+ export * from "./fail.js";
46
+ export * from "./unimplemented.js";
47
+ export * from "./unreachable.js";
@@ -0,0 +1,37 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { equal } from "./equal.js";
5
+ import { AssertionError } from "./assertion_error.js";
6
+ import { format } from "../../internal/1.0.12/format.js";
7
+
8
+ /**
9
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
10
+ * If not then throw.
11
+ *
12
+ * Type parameter can be specified to ensure values under comparison have the same type.
13
+ *
14
+ * @example Usage
15
+ * ```ts ignore
16
+ * import { assertNotEquals } from "@std/assert";
17
+ *
18
+ * assertNotEquals(1, 2); // Doesn't throw
19
+ * assertNotEquals(1, 1); // Throws
20
+ * ```
21
+ *
22
+ * @typeParam T The type of the values to compare.
23
+ * @param actual The actual value to compare.
24
+ * @param expected The expected value to compare.
25
+ * @param msg The optional message to display if the assertion fails.
26
+ */
27
+ export function assertNotEquals<T>(actual: T, expected: T, msg?: string) {
28
+ if (!equal(actual, expected)) {
29
+ return;
30
+ }
31
+ const actualString = format(actual);
32
+ const expectedString = format(expected);
33
+ const msgSuffix = msg ? `: ${msg}` : ".";
34
+ throw new AssertionError(
35
+ `Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`,
36
+ );
37
+ }
@@ -0,0 +1,33 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { assertFalse } from "./false.js";
4
+
5
+ /**
6
+ * Make an assertion that `obj` is not an instance of `type`.
7
+ * If so, then throw.
8
+ *
9
+ * @example Usage
10
+ * ```ts ignore
11
+ * import { assertNotInstanceOf } from "@std/assert";
12
+ *
13
+ * assertNotInstanceOf(new Date(), Number); // Doesn't throw
14
+ * assertNotInstanceOf(new Date(), Date); // Throws
15
+ * ```
16
+ *
17
+ * @typeParam A The type of the object to check.
18
+ * @typeParam T The type of the class to check against.
19
+ * @param actual The object to check.
20
+ * @param unexpectedType The class constructor to check against.
21
+ * @param msg The optional message to display if the assertion fails.
22
+ */
23
+ export function assertNotInstanceOf<A, T>(
24
+ actual: A,
25
+ // deno-lint-ignore no-explicit-any
26
+ unexpectedType: abstract new (...args: any[]) => T,
27
+ msg?: string,
28
+ ): asserts actual is Exclude<A, T> {
29
+ const msgSuffix = msg ? `: ${msg}` : ".";
30
+ msg =
31
+ `Expected object to not be an instance of "${typeof unexpectedType}"${msgSuffix}`;
32
+ assertFalse(actual instanceof unexpectedType, msg);
33
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { AssertionError } from "./assertion_error.js";
4
+
5
+ /**
6
+ * Make an assertion that `actual` not match RegExp `expected`. If match
7
+ * then throw.
8
+ *
9
+ * @example Usage
10
+ * ```ts ignore
11
+ * import { assertNotMatch } from "@std/assert";
12
+ *
13
+ * assertNotMatch("Denosaurus", /Raptor/); // Doesn't throw
14
+ * assertNotMatch("Raptor", /Raptor/); // Throws
15
+ * ```
16
+ *
17
+ * @param actual The actual value to match.
18
+ * @param expected The expected value to not match.
19
+ * @param msg The optional message to display if the assertion fails.
20
+ */
21
+ export function assertNotMatch(
22
+ actual: string,
23
+ expected: RegExp,
24
+ msg?: string,
25
+ ) {
26
+ if (!expected.test(actual)) return;
27
+ const msgSuffix = msg ? `: ${msg}` : ".";
28
+ msg = `Expected actual: "${actual}" to not match: "${expected}"${msgSuffix}`;
29
+ throw new AssertionError(msg);
30
+ }
@@ -0,0 +1,42 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import { AssertionError } from "./assertion_error.js";
4
+ import { format } from "../../internal/1.0.12/format.js";
5
+
6
+ /**
7
+ * Make an assertion that `actual` and `expected` are not strictly equal, using
8
+ * {@linkcode Object.is} for equality comparison. If the values are strictly
9
+ * equal then throw.
10
+ *
11
+ * @example Usage
12
+ * ```ts ignore
13
+ * import { assertNotStrictEquals } from "@std/assert";
14
+ *
15
+ * assertNotStrictEquals(1, 1); // Throws
16
+ * assertNotStrictEquals(1, 2); // Doesn't throw
17
+ *
18
+ * assertNotStrictEquals(0, 0); // Throws
19
+ * assertNotStrictEquals(0, -0); // Doesn't throw
20
+ * ```
21
+ *
22
+ * @typeParam T The type of the values to compare.
23
+ * @param actual The actual value to compare.
24
+ * @param expected The expected value to compare.
25
+ * @param msg The optional message to display if the assertion fails.
26
+ */
27
+ export function assertNotStrictEquals<T>(
28
+ actual: T,
29
+ expected: T,
30
+ msg?: string,
31
+ ) {
32
+ if (!Object.is(actual, expected)) {
33
+ return;
34
+ }
35
+
36
+ const msgSuffix = msg ? `: ${msg}` : ".";
37
+ throw new AssertionError(
38
+ `Expected "actual" to not be strictly equal to: ${
39
+ format(actual)
40
+ }${msgSuffix}\n`,
41
+ );
42
+ }