bupkis 0.18.1 → 0.18.2

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 (376) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -4
  3. package/src/assertion/assertion-types.ts +4 -4
  4. package/src/assertion/impl/sync-parametric.ts +1 -1
  5. package/src/expect.ts +0 -4
  6. package/src/guards.ts +24 -24
  7. package/src/internal-schema.ts +16 -32
  8. package/src/value-to-schema.ts +1 -1
  9. package/dist/assertion/assertion-async.cjs +0 -268
  10. package/dist/assertion/assertion-async.cjs.map +0 -1
  11. package/dist/assertion/assertion-async.d.cts +0 -40
  12. package/dist/assertion/assertion-async.d.cts.map +0 -1
  13. package/dist/assertion/assertion-async.d.ts +0 -40
  14. package/dist/assertion/assertion-async.d.ts.map +0 -1
  15. package/dist/assertion/assertion-async.js +0 -259
  16. package/dist/assertion/assertion-async.js.map +0 -1
  17. package/dist/assertion/assertion-standard-schema-async.cjs +0 -132
  18. package/dist/assertion/assertion-standard-schema-async.cjs.map +0 -1
  19. package/dist/assertion/assertion-standard-schema-async.d.cts +0 -52
  20. package/dist/assertion/assertion-standard-schema-async.d.cts.map +0 -1
  21. package/dist/assertion/assertion-standard-schema-async.d.ts +0 -52
  22. package/dist/assertion/assertion-standard-schema-async.d.ts.map +0 -1
  23. package/dist/assertion/assertion-standard-schema-async.js +0 -128
  24. package/dist/assertion/assertion-standard-schema-async.js.map +0 -1
  25. package/dist/assertion/assertion-standard-schema-sync.cjs +0 -141
  26. package/dist/assertion/assertion-standard-schema-sync.cjs.map +0 -1
  27. package/dist/assertion/assertion-standard-schema-sync.d.cts +0 -52
  28. package/dist/assertion/assertion-standard-schema-sync.d.cts.map +0 -1
  29. package/dist/assertion/assertion-standard-schema-sync.d.ts +0 -52
  30. package/dist/assertion/assertion-standard-schema-sync.d.ts.map +0 -1
  31. package/dist/assertion/assertion-standard-schema-sync.js +0 -137
  32. package/dist/assertion/assertion-standard-schema-sync.js.map +0 -1
  33. package/dist/assertion/assertion-sync.cjs +0 -284
  34. package/dist/assertion/assertion-sync.cjs.map +0 -1
  35. package/dist/assertion/assertion-sync.d.cts +0 -60
  36. package/dist/assertion/assertion-sync.d.cts.map +0 -1
  37. package/dist/assertion/assertion-sync.d.ts +0 -60
  38. package/dist/assertion/assertion-sync.d.ts.map +0 -1
  39. package/dist/assertion/assertion-sync.js +0 -275
  40. package/dist/assertion/assertion-sync.js.map +0 -1
  41. package/dist/assertion/assertion-types.cjs +0 -20
  42. package/dist/assertion/assertion-types.cjs.map +0 -1
  43. package/dist/assertion/assertion-types.d.cts +0 -1086
  44. package/dist/assertion/assertion-types.d.cts.map +0 -1
  45. package/dist/assertion/assertion-types.d.ts +0 -1086
  46. package/dist/assertion/assertion-types.d.ts.map +0 -1
  47. package/dist/assertion/assertion-types.js +0 -19
  48. package/dist/assertion/assertion-types.js.map +0 -1
  49. package/dist/assertion/assertion.cjs +0 -382
  50. package/dist/assertion/assertion.cjs.map +0 -1
  51. package/dist/assertion/assertion.d.cts +0 -109
  52. package/dist/assertion/assertion.d.cts.map +0 -1
  53. package/dist/assertion/assertion.d.ts +0 -109
  54. package/dist/assertion/assertion.d.ts.map +0 -1
  55. package/dist/assertion/assertion.js +0 -375
  56. package/dist/assertion/assertion.js.map +0 -1
  57. package/dist/assertion/create.cjs +0 -148
  58. package/dist/assertion/create.cjs.map +0 -1
  59. package/dist/assertion/create.d.cts +0 -85
  60. package/dist/assertion/create.d.cts.map +0 -1
  61. package/dist/assertion/create.d.ts +0 -85
  62. package/dist/assertion/create.d.ts.map +0 -1
  63. package/dist/assertion/create.js +0 -143
  64. package/dist/assertion/create.js.map +0 -1
  65. package/dist/assertion/format-assertion-failure.cjs +0 -63
  66. package/dist/assertion/format-assertion-failure.cjs.map +0 -1
  67. package/dist/assertion/format-assertion-failure.d.cts +0 -21
  68. package/dist/assertion/format-assertion-failure.d.cts.map +0 -1
  69. package/dist/assertion/format-assertion-failure.d.ts +0 -21
  70. package/dist/assertion/format-assertion-failure.d.ts.map +0 -1
  71. package/dist/assertion/format-assertion-failure.js +0 -59
  72. package/dist/assertion/format-assertion-failure.js.map +0 -1
  73. package/dist/assertion/impl/assertion-util.cjs +0 -68
  74. package/dist/assertion/impl/assertion-util.cjs.map +0 -1
  75. package/dist/assertion/impl/assertion-util.d.cts +0 -36
  76. package/dist/assertion/impl/assertion-util.d.cts.map +0 -1
  77. package/dist/assertion/impl/assertion-util.d.ts +0 -36
  78. package/dist/assertion/impl/assertion-util.d.ts.map +0 -1
  79. package/dist/assertion/impl/assertion-util.js +0 -62
  80. package/dist/assertion/impl/assertion-util.js.map +0 -1
  81. package/dist/assertion/impl/async-iterable.cjs +0 -627
  82. package/dist/assertion/impl/async-iterable.cjs.map +0 -1
  83. package/dist/assertion/impl/async-iterable.d.cts +0 -406
  84. package/dist/assertion/impl/async-iterable.d.cts.map +0 -1
  85. package/dist/assertion/impl/async-iterable.d.ts +0 -406
  86. package/dist/assertion/impl/async-iterable.d.ts.map +0 -1
  87. package/dist/assertion/impl/async-iterable.js +0 -624
  88. package/dist/assertion/impl/async-iterable.js.map +0 -1
  89. package/dist/assertion/impl/async-parametric.cjs +0 -412
  90. package/dist/assertion/impl/async-parametric.cjs.map +0 -1
  91. package/dist/assertion/impl/async-parametric.d.cts +0 -278
  92. package/dist/assertion/impl/async-parametric.d.cts.map +0 -1
  93. package/dist/assertion/impl/async-parametric.d.ts +0 -278
  94. package/dist/assertion/impl/async-parametric.d.ts.map +0 -1
  95. package/dist/assertion/impl/async-parametric.js +0 -409
  96. package/dist/assertion/impl/async-parametric.js.map +0 -1
  97. package/dist/assertion/impl/async.cjs +0 -56
  98. package/dist/assertion/impl/async.cjs.map +0 -1
  99. package/dist/assertion/impl/async.d.cts +0 -179
  100. package/dist/assertion/impl/async.d.cts.map +0 -1
  101. package/dist/assertion/impl/async.d.ts +0 -179
  102. package/dist/assertion/impl/async.d.ts.map +0 -1
  103. package/dist/assertion/impl/async.js +0 -39
  104. package/dist/assertion/impl/async.js.map +0 -1
  105. package/dist/assertion/impl/index.cjs +0 -37
  106. package/dist/assertion/impl/index.cjs.map +0 -1
  107. package/dist/assertion/impl/index.d.cts +0 -21
  108. package/dist/assertion/impl/index.d.cts.map +0 -1
  109. package/dist/assertion/impl/index.d.ts +0 -21
  110. package/dist/assertion/impl/index.d.ts.map +0 -1
  111. package/dist/assertion/impl/index.js +0 -21
  112. package/dist/assertion/impl/index.js.map +0 -1
  113. package/dist/assertion/impl/iteration-util.cjs +0 -297
  114. package/dist/assertion/impl/iteration-util.cjs.map +0 -1
  115. package/dist/assertion/impl/iteration-util.d.cts +0 -12
  116. package/dist/assertion/impl/iteration-util.d.cts.map +0 -1
  117. package/dist/assertion/impl/iteration-util.d.ts +0 -12
  118. package/dist/assertion/impl/iteration-util.d.ts.map +0 -1
  119. package/dist/assertion/impl/iteration-util.js +0 -282
  120. package/dist/assertion/impl/iteration-util.js.map +0 -1
  121. package/dist/assertion/impl/snapshot.cjs +0 -276
  122. package/dist/assertion/impl/snapshot.cjs.map +0 -1
  123. package/dist/assertion/impl/snapshot.d.cts +0 -278
  124. package/dist/assertion/impl/snapshot.d.cts.map +0 -1
  125. package/dist/assertion/impl/snapshot.d.ts +0 -278
  126. package/dist/assertion/impl/snapshot.d.ts.map +0 -1
  127. package/dist/assertion/impl/snapshot.js +0 -273
  128. package/dist/assertion/impl/snapshot.js.map +0 -1
  129. package/dist/assertion/impl/sync-basic.cjs +0 -553
  130. package/dist/assertion/impl/sync-basic.cjs.map +0 -1
  131. package/dist/assertion/impl/sync-basic.d.cts +0 -528
  132. package/dist/assertion/impl/sync-basic.d.cts.map +0 -1
  133. package/dist/assertion/impl/sync-basic.d.ts +0 -528
  134. package/dist/assertion/impl/sync-basic.d.ts.map +0 -1
  135. package/dist/assertion/impl/sync-basic.js +0 -550
  136. package/dist/assertion/impl/sync-basic.js.map +0 -1
  137. package/dist/assertion/impl/sync-collection.cjs +0 -856
  138. package/dist/assertion/impl/sync-collection.cjs.map +0 -1
  139. package/dist/assertion/impl/sync-collection.d.cts +0 -607
  140. package/dist/assertion/impl/sync-collection.d.cts.map +0 -1
  141. package/dist/assertion/impl/sync-collection.d.ts +0 -607
  142. package/dist/assertion/impl/sync-collection.d.ts.map +0 -1
  143. package/dist/assertion/impl/sync-collection.js +0 -850
  144. package/dist/assertion/impl/sync-collection.js.map +0 -1
  145. package/dist/assertion/impl/sync-date.cjs +0 -341
  146. package/dist/assertion/impl/sync-date.cjs.map +0 -1
  147. package/dist/assertion/impl/sync-date.d.cts +0 -209
  148. package/dist/assertion/impl/sync-date.d.cts.map +0 -1
  149. package/dist/assertion/impl/sync-date.d.ts +0 -209
  150. package/dist/assertion/impl/sync-date.d.ts.map +0 -1
  151. package/dist/assertion/impl/sync-date.js +0 -338
  152. package/dist/assertion/impl/sync-date.js.map +0 -1
  153. package/dist/assertion/impl/sync-esoteric.cjs +0 -214
  154. package/dist/assertion/impl/sync-esoteric.cjs.map +0 -1
  155. package/dist/assertion/impl/sync-esoteric.d.cts +0 -191
  156. package/dist/assertion/impl/sync-esoteric.d.cts.map +0 -1
  157. package/dist/assertion/impl/sync-esoteric.d.ts +0 -191
  158. package/dist/assertion/impl/sync-esoteric.d.ts.map +0 -1
  159. package/dist/assertion/impl/sync-esoteric.js +0 -211
  160. package/dist/assertion/impl/sync-esoteric.js.map +0 -1
  161. package/dist/assertion/impl/sync-iterable.cjs +0 -512
  162. package/dist/assertion/impl/sync-iterable.cjs.map +0 -1
  163. package/dist/assertion/impl/sync-iterable.d.cts +0 -334
  164. package/dist/assertion/impl/sync-iterable.d.cts.map +0 -1
  165. package/dist/assertion/impl/sync-iterable.d.ts +0 -334
  166. package/dist/assertion/impl/sync-iterable.d.ts.map +0 -1
  167. package/dist/assertion/impl/sync-iterable.js +0 -509
  168. package/dist/assertion/impl/sync-iterable.js.map +0 -1
  169. package/dist/assertion/impl/sync-parametric.cjs +0 -805
  170. package/dist/assertion/impl/sync-parametric.cjs.map +0 -1
  171. package/dist/assertion/impl/sync-parametric.d.cts +0 -560
  172. package/dist/assertion/impl/sync-parametric.d.cts.map +0 -1
  173. package/dist/assertion/impl/sync-parametric.d.ts +0 -560
  174. package/dist/assertion/impl/sync-parametric.d.ts.map +0 -1
  175. package/dist/assertion/impl/sync-parametric.js +0 -802
  176. package/dist/assertion/impl/sync-parametric.js.map +0 -1
  177. package/dist/assertion/impl/sync.cjs +0 -214
  178. package/dist/assertion/impl/sync.cjs.map +0 -1
  179. package/dist/assertion/impl/sync.d.cts +0 -512
  180. package/dist/assertion/impl/sync.d.cts.map +0 -1
  181. package/dist/assertion/impl/sync.d.ts +0 -512
  182. package/dist/assertion/impl/sync.d.ts.map +0 -1
  183. package/dist/assertion/impl/sync.js +0 -197
  184. package/dist/assertion/impl/sync.js.map +0 -1
  185. package/dist/assertion/index.cjs +0 -38
  186. package/dist/assertion/index.cjs.map +0 -1
  187. package/dist/assertion/index.d.cts +0 -18
  188. package/dist/assertion/index.d.cts.map +0 -1
  189. package/dist/assertion/index.d.ts +0 -18
  190. package/dist/assertion/index.d.ts.map +0 -1
  191. package/dist/assertion/index.js +0 -17
  192. package/dist/assertion/index.js.map +0 -1
  193. package/dist/assertion/slotify.cjs +0 -165
  194. package/dist/assertion/slotify.cjs.map +0 -1
  195. package/dist/assertion/slotify.d.cts +0 -11
  196. package/dist/assertion/slotify.d.cts.map +0 -1
  197. package/dist/assertion/slotify.d.ts +0 -11
  198. package/dist/assertion/slotify.d.ts.map +0 -1
  199. package/dist/assertion/slotify.js +0 -161
  200. package/dist/assertion/slotify.js.map +0 -1
  201. package/dist/bootstrap.cjs +0 -43
  202. package/dist/bootstrap.cjs.map +0 -1
  203. package/dist/bootstrap.d.cts +0 -27
  204. package/dist/bootstrap.d.cts.map +0 -1
  205. package/dist/bootstrap.d.ts +0 -27
  206. package/dist/bootstrap.d.ts.map +0 -1
  207. package/dist/bootstrap.js +0 -40
  208. package/dist/bootstrap.js.map +0 -1
  209. package/dist/constant.cjs +0 -82
  210. package/dist/constant.cjs.map +0 -1
  211. package/dist/constant.d.cts +0 -69
  212. package/dist/constant.d.cts.map +0 -1
  213. package/dist/constant.d.ts +0 -69
  214. package/dist/constant.d.ts.map +0 -1
  215. package/dist/constant.js +0 -79
  216. package/dist/constant.js.map +0 -1
  217. package/dist/diff.cjs +0 -340
  218. package/dist/diff.cjs.map +0 -1
  219. package/dist/diff.d.cts +0 -51
  220. package/dist/diff.d.cts.map +0 -1
  221. package/dist/diff.d.ts +0 -51
  222. package/dist/diff.d.ts.map +0 -1
  223. package/dist/diff.js +0 -334
  224. package/dist/diff.js.map +0 -1
  225. package/dist/error.cjs +0 -204
  226. package/dist/error.cjs.map +0 -1
  227. package/dist/error.d.cts +0 -212
  228. package/dist/error.d.cts.map +0 -1
  229. package/dist/error.d.ts +0 -212
  230. package/dist/error.d.ts.map +0 -1
  231. package/dist/error.js +0 -191
  232. package/dist/error.js.map +0 -1
  233. package/dist/expect.cjs +0 -590
  234. package/dist/expect.cjs.map +0 -1
  235. package/dist/expect.d.cts +0 -138
  236. package/dist/expect.d.cts.map +0 -1
  237. package/dist/expect.d.ts +0 -138
  238. package/dist/expect.d.ts.map +0 -1
  239. package/dist/expect.js +0 -582
  240. package/dist/expect.js.map +0 -1
  241. package/dist/guards.cjs +0 -297
  242. package/dist/guards.cjs.map +0 -1
  243. package/dist/guards.d.cts +0 -231
  244. package/dist/guards.d.cts.map +0 -1
  245. package/dist/guards.d.ts +0 -231
  246. package/dist/guards.d.ts.map +0 -1
  247. package/dist/guards.js +0 -277
  248. package/dist/guards.js.map +0 -1
  249. package/dist/index.cjs +0 -111
  250. package/dist/index.cjs.map +0 -1
  251. package/dist/index.d.cts +0 -448
  252. package/dist/index.d.cts.map +0 -1
  253. package/dist/index.d.ts +0 -448
  254. package/dist/index.d.ts.map +0 -1
  255. package/dist/index.js +0 -71
  256. package/dist/index.js.map +0 -1
  257. package/dist/internal-schema.cjs +0 -253
  258. package/dist/internal-schema.cjs.map +0 -1
  259. package/dist/internal-schema.d.cts +0 -8
  260. package/dist/internal-schema.d.cts.map +0 -1
  261. package/dist/internal-schema.d.ts +0 -8
  262. package/dist/internal-schema.d.ts.map +0 -1
  263. package/dist/internal-schema.js +0 -248
  264. package/dist/internal-schema.js.map +0 -1
  265. package/dist/metadata.cjs +0 -57
  266. package/dist/metadata.cjs.map +0 -1
  267. package/dist/metadata.d.cts +0 -27
  268. package/dist/metadata.d.cts.map +0 -1
  269. package/dist/metadata.d.ts +0 -27
  270. package/dist/metadata.d.ts.map +0 -1
  271. package/dist/metadata.js +0 -54
  272. package/dist/metadata.js.map +0 -1
  273. package/dist/schema.cjs +0 -1522
  274. package/dist/schema.cjs.map +0 -1
  275. package/dist/schema.d.cts +0 -1196
  276. package/dist/schema.d.cts.map +0 -1
  277. package/dist/schema.d.ts +0 -1196
  278. package/dist/schema.d.ts.map +0 -1
  279. package/dist/schema.js +0 -1516
  280. package/dist/schema.js.map +0 -1
  281. package/dist/snapshot/adapter.cjs +0 -31
  282. package/dist/snapshot/adapter.cjs.map +0 -1
  283. package/dist/snapshot/adapter.d.cts +0 -258
  284. package/dist/snapshot/adapter.d.cts.map +0 -1
  285. package/dist/snapshot/adapter.d.ts +0 -258
  286. package/dist/snapshot/adapter.d.ts.map +0 -1
  287. package/dist/snapshot/adapter.js +0 -27
  288. package/dist/snapshot/adapter.js.map +0 -1
  289. package/dist/snapshot/adapters/fallback.cjs +0 -453
  290. package/dist/snapshot/adapters/fallback.cjs.map +0 -1
  291. package/dist/snapshot/adapters/fallback.d.cts +0 -185
  292. package/dist/snapshot/adapters/fallback.d.cts.map +0 -1
  293. package/dist/snapshot/adapters/fallback.d.ts +0 -185
  294. package/dist/snapshot/adapters/fallback.d.ts.map +0 -1
  295. package/dist/snapshot/adapters/fallback.js +0 -446
  296. package/dist/snapshot/adapters/fallback.js.map +0 -1
  297. package/dist/snapshot/adapters/node-test.cjs +0 -301
  298. package/dist/snapshot/adapters/node-test.cjs.map +0 -1
  299. package/dist/snapshot/adapters/node-test.d.cts +0 -131
  300. package/dist/snapshot/adapters/node-test.d.cts.map +0 -1
  301. package/dist/snapshot/adapters/node-test.d.ts +0 -131
  302. package/dist/snapshot/adapters/node-test.d.ts.map +0 -1
  303. package/dist/snapshot/adapters/node-test.js +0 -297
  304. package/dist/snapshot/adapters/node-test.js.map +0 -1
  305. package/dist/snapshot/index.cjs +0 -61
  306. package/dist/snapshot/index.cjs.map +0 -1
  307. package/dist/snapshot/index.d.cts +0 -40
  308. package/dist/snapshot/index.d.cts.map +0 -1
  309. package/dist/snapshot/index.d.ts +0 -40
  310. package/dist/snapshot/index.d.ts.map +0 -1
  311. package/dist/snapshot/index.js +0 -44
  312. package/dist/snapshot/index.js.map +0 -1
  313. package/dist/snapshot/node-version.cjs +0 -49
  314. package/dist/snapshot/node-version.cjs.map +0 -1
  315. package/dist/snapshot/node-version.d.cts +0 -34
  316. package/dist/snapshot/node-version.d.cts.map +0 -1
  317. package/dist/snapshot/node-version.d.ts +0 -34
  318. package/dist/snapshot/node-version.d.ts.map +0 -1
  319. package/dist/snapshot/node-version.js +0 -44
  320. package/dist/snapshot/node-version.js.map +0 -1
  321. package/dist/snapshot/select-adapter.cjs +0 -170
  322. package/dist/snapshot/select-adapter.cjs.map +0 -1
  323. package/dist/snapshot/select-adapter.d.cts +0 -128
  324. package/dist/snapshot/select-adapter.d.cts.map +0 -1
  325. package/dist/snapshot/select-adapter.d.ts +0 -128
  326. package/dist/snapshot/select-adapter.d.ts.map +0 -1
  327. package/dist/snapshot/select-adapter.js +0 -164
  328. package/dist/snapshot/select-adapter.js.map +0 -1
  329. package/dist/snapshot/serializer.cjs +0 -246
  330. package/dist/snapshot/serializer.cjs.map +0 -1
  331. package/dist/snapshot/serializer.d.cts +0 -126
  332. package/dist/snapshot/serializer.d.cts.map +0 -1
  333. package/dist/snapshot/serializer.d.ts +0 -126
  334. package/dist/snapshot/serializer.d.ts.map +0 -1
  335. package/dist/snapshot/serializer.js +0 -238
  336. package/dist/snapshot/serializer.js.map +0 -1
  337. package/dist/standard-schema.cjs +0 -13
  338. package/dist/standard-schema.cjs.map +0 -1
  339. package/dist/standard-schema.d.cts +0 -192
  340. package/dist/standard-schema.d.cts.map +0 -1
  341. package/dist/standard-schema.d.ts +0 -192
  342. package/dist/standard-schema.d.ts.map +0 -1
  343. package/dist/standard-schema.js +0 -12
  344. package/dist/standard-schema.js.map +0 -1
  345. package/dist/types.cjs +0 -22
  346. package/dist/types.cjs.map +0 -1
  347. package/dist/types.d.cts +0 -905
  348. package/dist/types.d.cts.map +0 -1
  349. package/dist/types.d.ts +0 -905
  350. package/dist/types.d.ts.map +0 -1
  351. package/dist/types.js +0 -21
  352. package/dist/types.js.map +0 -1
  353. package/dist/use.cjs +0 -240
  354. package/dist/use.cjs.map +0 -1
  355. package/dist/use.d.cts +0 -8
  356. package/dist/use.d.cts.map +0 -1
  357. package/dist/use.d.ts +0 -8
  358. package/dist/use.d.ts.map +0 -1
  359. package/dist/use.js +0 -236
  360. package/dist/use.js.map +0 -1
  361. package/dist/util.cjs +0 -255
  362. package/dist/util.cjs.map +0 -1
  363. package/dist/util.d.cts +0 -141
  364. package/dist/util.d.cts.map +0 -1
  365. package/dist/util.d.ts +0 -141
  366. package/dist/util.d.ts.map +0 -1
  367. package/dist/util.js +0 -234
  368. package/dist/util.js.map +0 -1
  369. package/dist/value-to-schema.cjs +0 -537
  370. package/dist/value-to-schema.cjs.map +0 -1
  371. package/dist/value-to-schema.d.cts +0 -144
  372. package/dist/value-to-schema.d.cts.map +0 -1
  373. package/dist/value-to-schema.d.ts +0 -144
  374. package/dist/value-to-schema.d.ts.map +0 -1
  375. package/dist/value-to-schema.js +0 -533
  376. package/dist/value-to-schema.js.map +0 -1
@@ -1,805 +0,0 @@
1
- "use strict";
2
- /**
3
- * Parameterized assertions for comparisons, function behavior, and complex
4
- * validation.
5
- *
6
- * These assertions accept additional parameters to customize their behavior,
7
- * including numeric comparisons, string matching, object satisfaction, function
8
- * throwing behavior, and deep equality checks.
9
- *
10
- * @packageDocumentation
11
- * @groupDescription Parametric Assertions (Sync)
12
- * Complex assertions that accept parameters for customized validation behavior.
13
- *
14
- * @showGroups
15
- */
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.satisfiesAssertion = exports.stringLengthAssertion = exports.stringMatchesAssertion = exports.stringIncludesAssertion = exports.functionThrowsTypeSatisfyingAssertion = exports.functionThrowsSatisfyingAssertion = exports.functionThrowsTypeAssertion = exports.functionThrowsAssertion = exports.deepEqualAssertion = exports.strictEqualityAssertion = exports.errorMessageMatchingAssertion = exports.errorMessageAssertion = exports.functionArityAssertion = exports.oneOfAssertion = exports.stringEndsWithAssertion = exports.stringBeginsWithAssertion = exports.stringLessThanOrEqualAssertion = exports.stringGreaterThanOrEqualAssertion = exports.stringLessThanAssertion = exports.stringGreaterThanAssertion = exports.numberCloseToAssertion = exports.numberWithinRangeAssertion = exports.numberLessThanOrEqualAssertion = exports.numberGreaterThanOrEqualAssertion = exports.numberLessThanAssertion = exports.numberGreaterThanAssertion = exports.typeOfAssertion = exports.instanceOfAssertion = void 0;
18
- const node_util_1 = require("node:util");
19
- const zod_1 = require("zod");
20
- const error_js_1 = require("../../error.cjs");
21
- const guards_js_1 = require("../../guards.cjs");
22
- const schema_js_1 = require("../../schema.cjs");
23
- const value_to_schema_js_1 = require("../../value-to-schema.cjs");
24
- const create_js_1 = require("../create.cjs");
25
- const assertion_util_js_1 = require("./assertion-util.cjs");
26
- const { freeze } = Object;
27
- const { abs } = Math;
28
- /**
29
- * For {@link typeOfAssertion}
30
- */
31
- const knownTypes = freeze(new Set([
32
- 'string',
33
- 'number',
34
- 'boolean',
35
- 'undefined',
36
- 'null',
37
- 'BigInt',
38
- 'Symbol',
39
- 'Object',
40
- 'Function',
41
- 'Array',
42
- 'Date',
43
- 'Map',
44
- 'Set',
45
- 'WeakMap',
46
- 'WeakSet',
47
- 'RegExp',
48
- 'Promise',
49
- 'Error',
50
- 'WeakRef',
51
- ]));
52
- /**
53
- * Assertion for testing if a value is an instance of a specific constructor.
54
- *
55
- * @example
56
- *
57
- * ```typescript
58
- * expect(new Date(), 'to be an instance of', Date); // passes
59
- * expect('hello', 'to be a', String); // fails
60
- * ```
61
- *
62
- * @group Parametric Assertions (Sync)
63
- */
64
- exports.instanceOfAssertion = (0, create_js_1.createAssertion)([['to be an instance of', 'to be a', 'to be an'], schema_js_1.ConstructibleSchema], (_, ctor) => createInstanceOfSchema(ctor));
65
- /**
66
- * Assertion for testing if a value is of a specific built-in type.
67
- *
68
- * @example
69
- *
70
- * ```typescript
71
- * expect('hello', 'to be a', 'string'); // passes
72
- * expect(42, 'to be an', 'Array'); // fails
73
- * expect([], 'to be a', 'array'); // passes
74
- * ```
75
- *
76
- * @group Parametric Assertions (Sync)
77
- */
78
- exports.typeOfAssertion = (0, create_js_1.createAssertion)([
79
- schema_js_1.UnknownSchema,
80
- ['to be a', 'to be an', 'to have type'],
81
- zod_1.z.enum([...knownTypes].flatMap((t) => [t, t.toLowerCase()])),
82
- ], (_, type) => {
83
- type = type.toLowerCase();
84
- // these first three are names that are _not_ results of the `typeof` operator; i.e. `typeof x` will never return these strings
85
- switch (type) {
86
- case 'array':
87
- return schema_js_1.UnknownArraySchema;
88
- case 'bigint':
89
- return schema_js_1.BigintSchema;
90
- case 'boolean':
91
- return schema_js_1.BooleanSchema;
92
- case 'date':
93
- return schema_js_1.DateSchema;
94
- case 'error':
95
- return schema_js_1.ErrorSchema;
96
- case 'function':
97
- return schema_js_1.FunctionSchema;
98
- case 'map':
99
- return schema_js_1.MapSchema;
100
- case 'null':
101
- return schema_js_1.NullSchema;
102
- case 'number':
103
- return schema_js_1.NumberSchema;
104
- case 'object':
105
- return schema_js_1.AnyObjectSchema;
106
- case 'promise':
107
- return schema_js_1.WrappedPromiseLikeSchema;
108
- case 'regex': // fallthrough
109
- case 'regexp':
110
- return schema_js_1.RegExpSchema;
111
- case 'set':
112
- return schema_js_1.SetSchema;
113
- case 'string':
114
- return schema_js_1.StringSchema;
115
- case 'symbol':
116
- return schema_js_1.SymbolSchema;
117
- case 'undefined':
118
- return schema_js_1.UndefinedSchema;
119
- case 'weakmap':
120
- return schema_js_1.WeakMapSchema;
121
- case 'weakref':
122
- return schema_js_1.WeakRefSchema;
123
- case 'weakset':
124
- return schema_js_1.WeakSetSchema;
125
- // c8 ignore next 2
126
- default:
127
- throw new error_js_1.BupkisError(`Unknown "type": "${type}"`);
128
- }
129
- });
130
- /**
131
- * Assertion for testing if a number is greater than another number.
132
- *
133
- * @example
134
- *
135
- * ```typescript
136
- * expect(5, 'to be greater than', 3); // passes
137
- * expect(2, 'to be greater than', 5); // fails
138
- * ```
139
- *
140
- * @group Parametric Assertions (Sync)
141
- */
142
- exports.numberGreaterThanAssertion = (0, create_js_1.createAssertion)([schema_js_1.NumberSchema, 'to be greater than', schema_js_1.NumberSchema], (_, other) => schema_js_1.NumberSchema.gt(other));
143
- /**
144
- * Assertion for testing if a number is less than another number.
145
- *
146
- * @example
147
- *
148
- * ```typescript
149
- * expect(3, 'to be less than', 5); // passes
150
- * expect(5, 'to be less than', 2); // fails
151
- * ```
152
- *
153
- * @group Parametric Assertions (Sync)
154
- */
155
- exports.numberLessThanAssertion = (0, create_js_1.createAssertion)([schema_js_1.NumberSchema, ['to be less than', 'to be lt'], schema_js_1.NumberSchema], (_, other) => schema_js_1.NumberSchema.lt(other));
156
- /**
157
- * Assertion for testing if a number is greater than or equal to another number.
158
- *
159
- * @example
160
- *
161
- * ```typescript
162
- * expect(5, 'to be greater than or equal to', 5); // passes
163
- * expect(5, 'to be at least', 3); // passes
164
- * expect(2, 'to be at least', 5); // fails
165
- * ```
166
- *
167
- * @group Parametric Assertions (Sync)
168
- */
169
- exports.numberGreaterThanOrEqualAssertion = (0, create_js_1.createAssertion)([
170
- schema_js_1.NumberSchema,
171
- ['to be greater than or equal to', 'to be at least', 'to be gte'],
172
- schema_js_1.NumberSchema,
173
- ], (_, other) => schema_js_1.NumberSchema.gte(other));
174
- /**
175
- * Assertion for testing if a number is less than or equal to another number.
176
- *
177
- * @example
178
- *
179
- * ```typescript
180
- * expect(3, 'to be less than or equal to', 5); // passes
181
- * expect(5, 'to be at most', 5); // passes
182
- * expect(7, 'to be at most', 5); // fails
183
- * ```
184
- *
185
- * @group Parametric Assertions (Sync)
186
- */
187
- exports.numberLessThanOrEqualAssertion = (0, create_js_1.createAssertion)([
188
- schema_js_1.NumberSchema,
189
- ['to be less than or equal to', 'to be at most', 'to be lte'],
190
- schema_js_1.NumberSchema,
191
- ], (_, other) => schema_js_1.NumberSchema.lte(other));
192
- /**
193
- * Assertion for testing if a number is within a specific range (inclusive).
194
- *
195
- * @example
196
- *
197
- * ```typescript
198
- * expect(5, 'to be within', 1, 10); // passes
199
- * expect(15, 'to be between', 1, 10); // fails
200
- * ```
201
- *
202
- * @group Parametric Assertions (Sync)
203
- */
204
- exports.numberWithinRangeAssertion = (0, create_js_1.createAssertion)([schema_js_1.NumberSchema, ['to be within', 'to be between'], schema_js_1.NumberSchema, schema_js_1.NumberSchema], (subject, min, max) => {
205
- if (subject < min || subject > max) {
206
- return {
207
- message: `Expected ${subject} to be within range [${min}, ${max}]`,
208
- };
209
- }
210
- });
211
- /**
212
- * Assertion for testing if a number is close to another number within a
213
- * tolerance.
214
- *
215
- * @example
216
- *
217
- * ```typescript
218
- * expect(1.0001, 'to be close to', 1.0, 0.001); // passes
219
- * expect(1.1, 'to be close to', 1.0, 0.01); // fails
220
- * ```
221
- *
222
- * @group Parametric Assertions (Sync)
223
- */
224
- exports.numberCloseToAssertion = (0, create_js_1.createAssertion)([schema_js_1.NumberSchema, 'to be close to', schema_js_1.NumberSchema, schema_js_1.NumberSchema.optional()], (subject, expected, tolerance = 1e-9) => {
225
- const diff = abs(subject - expected);
226
- if (diff > tolerance) {
227
- return {
228
- actual: subject,
229
- expected,
230
- message: `Expected ${subject} to be close to ${expected} (within ${tolerance}), but difference was ${diff}`,
231
- };
232
- }
233
- });
234
- /**
235
- * Assertion for testing if a string is lexicographically greater than another
236
- * string.
237
- *
238
- * @example
239
- *
240
- * ```typescript
241
- * expect('b', 'to be greater than', 'a'); // passes
242
- * expect('apple', 'to be greater than', 'banana'); // fails
243
- * ```
244
- *
245
- * @group Parametric Assertions (Sync)
246
- */
247
- exports.stringGreaterThanAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to be greater than', schema_js_1.StringSchema], (subject, other) => {
248
- if (!(subject > other)) {
249
- return {
250
- message: `Expected "${subject}" to be greater than "${other}"`,
251
- };
252
- }
253
- });
254
- /**
255
- * Assertion for testing if a string is lexicographically less than another
256
- * string.
257
- *
258
- * @example
259
- *
260
- * ```typescript
261
- * expect('a', 'to be less than', 'b'); // passes
262
- * expect('banana', 'to be less than', 'apple'); // fails
263
- * ```
264
- *
265
- * @group Parametric Assertions (Sync)
266
- */
267
- exports.stringLessThanAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to be less than', schema_js_1.StringSchema], (subject, other) => {
268
- if (!(subject < other)) {
269
- return {
270
- message: `Expected "${subject}" to be less than "${other}"`,
271
- };
272
- }
273
- });
274
- /**
275
- * Assertion for testing if a string is lexicographically greater than or equal
276
- * to another string.
277
- *
278
- * @example
279
- *
280
- * ```typescript
281
- * expect('b', 'to be greater than or equal to', 'a'); // passes
282
- * expect('a', 'to be greater than or equal to', 'a'); // passes
283
- * expect('a', 'to be greater than or equal to', 'b'); // fails
284
- * ```
285
- *
286
- * @group Parametric Assertions (Sync)
287
- */
288
- exports.stringGreaterThanOrEqualAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to be greater than or equal to', schema_js_1.StringSchema], (subject, other) => {
289
- if (!(subject >= other)) {
290
- return {
291
- message: `Expected "${subject}" to be greater than or equal to "${other}"`,
292
- };
293
- }
294
- });
295
- /**
296
- * Assertion for testing if a string is lexicographically less than or equal to
297
- * another string.
298
- *
299
- * @example
300
- *
301
- * ```typescript
302
- * expect('a', 'to be less than or equal to', 'b'); // passes
303
- * expect('a', 'to be less than or equal to', 'a'); // passes
304
- * expect('b', 'to be less than or equal to', 'a'); // fails
305
- * ```
306
- *
307
- * @group Parametric Assertions (Sync)
308
- */
309
- exports.stringLessThanOrEqualAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to be less than or equal to', schema_js_1.StringSchema], (subject, other) => {
310
- if (!(subject <= other)) {
311
- return {
312
- message: `Expected "${subject}" to be less than or equal to "${other}"`,
313
- };
314
- }
315
- });
316
- /**
317
- * Assertion for testing if a string begins with a specific prefix.
318
- *
319
- * @example
320
- *
321
- * ```typescript
322
- * expect('hello world', 'to begin with', 'hello'); // passes
323
- * expect('hello world', 'to start with', 'world'); // fails
324
- * ```
325
- *
326
- * @group Parametric Assertions (Sync)
327
- */
328
- exports.stringBeginsWithAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, ['to begin with', 'to start with'], schema_js_1.StringSchema], (subject, prefix) => {
329
- if (!subject.startsWith(prefix)) {
330
- return {
331
- message: `Expected "${subject}" to begin with "${prefix}"`,
332
- };
333
- }
334
- });
335
- /**
336
- * Assertion for testing if a string ends with a specific suffix.
337
- *
338
- * @example
339
- *
340
- * ```typescript
341
- * expect('hello world', 'to end with', 'world'); // passes
342
- * expect('hello world', 'to end with', 'hello'); // fails
343
- * ```
344
- *
345
- * @group Parametric Assertions (Sync)
346
- */
347
- exports.stringEndsWithAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to end with', schema_js_1.StringSchema], (subject, suffix) => {
348
- if (!subject.endsWith(suffix)) {
349
- return {
350
- message: `Expected "${subject}" to end with "${suffix}"`,
351
- };
352
- }
353
- });
354
- /**
355
- * Assertion for testing if a value is one of a specific set of values.
356
- *
357
- * @example
358
- *
359
- * ```typescript
360
- * expect('red', 'to be one of', ['red', 'green', 'blue']); // passes
361
- * expect('yellow', 'to be one of', ['red', 'green', 'blue']); // fails
362
- * ```
363
- *
364
- * @group Parametric Assertions (Sync)
365
- */
366
- exports.oneOfAssertion = (0, create_js_1.createAssertion)(['to be one of', schema_js_1.UnknownArraySchema], (subject, values) => {
367
- if (!values.includes(subject)) {
368
- return {
369
- actual: subject,
370
- expected: values,
371
- message: `Expected ${(0, node_util_1.inspect)(subject)} to be one of [${values.map((v) => (0, node_util_1.inspect)(v)).join(', ')}]`,
372
- };
373
- }
374
- });
375
- /**
376
- * Assertion for testing if a function has a specific arity (number of
377
- * parameters).
378
- *
379
- * @example
380
- *
381
- * ```typescript
382
- * expect((a, b) => a + b, 'to have arity', 2); // passes
383
- * expect((a, b, c) => a + b + c, 'to have arity', 2); // fails
384
- * ```
385
- *
386
- * @group Parametric Assertions (Sync)
387
- */
388
- exports.functionArityAssertion = (0, create_js_1.createAssertion)([schema_js_1.FunctionSchema, 'to have arity', schema_js_1.NonNegativeIntegerSchema], (subject, expectedArity) => {
389
- if (subject.length !== expectedArity) {
390
- return {
391
- actual: subject.length,
392
- expected: expectedArity,
393
- message: `Expected function to have arity ${expectedArity}, but it has arity ${subject.length}`,
394
- };
395
- }
396
- });
397
- /**
398
- * Assertion for testing if an Error has a specific message.
399
- *
400
- * @example
401
- *
402
- * ```typescript
403
- * expect(new Error('oops'), 'to have message', 'oops'); // passes
404
- * expect(new Error('oops'), 'to have message', 'wrong'); // fails
405
- * ```
406
- *
407
- * @group Parametric Assertions (Sync)
408
- */
409
- exports.errorMessageAssertion = (0, create_js_1.createAssertion)([schema_js_1.ErrorSchema, 'to have message', schema_js_1.StringSchema], (subject, expectedMessage) => {
410
- if (subject.message !== expectedMessage) {
411
- return {
412
- actual: subject.message,
413
- expected: expectedMessage,
414
- message: `Expected error message "${subject.message}" to equal "${expectedMessage}"`,
415
- };
416
- }
417
- });
418
- /**
419
- * Assertion for testing if an Error has a message matching a regular
420
- * expression.
421
- *
422
- * @example
423
- *
424
- * ```typescript
425
- * expect(
426
- * new Error('Error: something went wrong'),
427
- * 'to have message matching',
428
- * /something/,
429
- * ); // passes
430
- * expect(new Error('All good'), 'to have message matching', /error/i); // fails
431
- * ```
432
- *
433
- * @group Parametric Assertions (Sync)
434
- */
435
- exports.errorMessageMatchingAssertion = (0, create_js_1.createAssertion)([schema_js_1.ErrorSchema, 'to have message matching', schema_js_1.RegExpSchema], (subject, pattern) => {
436
- if (!pattern.test(subject.message)) {
437
- return {
438
- message: `Expected error message "${subject.message}" to match ${pattern}`,
439
- };
440
- }
441
- });
442
- /**
443
- * Assertion for testing strict equality between two values.
444
- *
445
- * @example
446
- *
447
- * ```typescript
448
- * expect(42, 'to be', 42); // passes
449
- * expect('hello', 'to equal', 'hello'); // passes
450
- * expect({}, 'to be', {}); // fails (different object references)
451
- * ```
452
- *
453
- * @group Parametric Assertions (Sync)
454
- */
455
- exports.strictEqualityAssertion = (0, create_js_1.createAssertion)([
456
- [
457
- 'to be',
458
- 'to equal',
459
- 'equals',
460
- 'is',
461
- 'is equal to',
462
- 'to strictly equal',
463
- 'is strictly equal to',
464
- ],
465
- schema_js_1.UnknownSchema,
466
- ], (subject, value) => {
467
- if (subject !== value) {
468
- return {
469
- actual: subject,
470
- expected: value,
471
- message: `Expected ${(0, node_util_1.inspect)(subject)} to equal ${(0, node_util_1.inspect)(value)}`,
472
- };
473
- }
474
- });
475
- /**
476
- * Assertion for testing deep equality between any values.
477
- *
478
- * Works with primitives, objects, arrays, Maps, Sets, and other types.
479
- *
480
- * @example
481
- *
482
- * ```typescript
483
- * // Primitives
484
- * expect(42, 'to deep equal', 42); // passes
485
- * expect('hello', 'to deeply equal', 'world'); // fails
486
- *
487
- * // Objects
488
- * expect({ a: 1, b: 2 }, 'to deep equal', { a: 1, b: 2 }); // passes
489
- * expect({ a: 1 }, 'to deeply equal', { a: 1, b: 2 }); // fails
490
- *
491
- * // Arrays
492
- * expect([1, 2, 3], 'to deep equal', [1, 2, 3]); // passes
493
- *
494
- * // Maps and Sets
495
- * expect(new Map([['a', 1]]), 'to deep equal', new Map([['a', 1]])); // passes
496
- * expect(new Set([1, 2]), 'to deeply equal', new Set([1, 2])); // passes
497
- * ```
498
- *
499
- * @group Parametric Assertions (Sync)
500
- * @bupkisAnchor unknown-to-deep-equal-any
501
- * @bupkisAssertionCategory equality
502
- */
503
- exports.deepEqualAssertion = (0, create_js_1.createAssertion)([['to deep equal', 'to deeply equal'], schema_js_1.UnknownSchema], (_, expected) => (0, value_to_schema_js_1.valueToSchema)(expected, value_to_schema_js_1.valueToSchemaOptionsForDeepEqual));
504
- /**
505
- * Assertion for testing if a function throws an error when called.
506
- *
507
- * @example
508
- *
509
- * ```typescript
510
- * expect(() => {
511
- * throw new Error('oops');
512
- * }, 'to throw'); // passes
513
- * expect(() => 'hello', 'to throw'); // fails
514
- * ```
515
- *
516
- * @group Parametric Assertions (Sync)
517
- * @bupkisAnchor function-to-throw-any
518
- * @bupkisAssertionCategory function
519
- * @bupkisRedirect to-throw
520
- */
521
- exports.functionThrowsAssertion = (0, create_js_1.createAssertion)([schema_js_1.FunctionSchema, 'to throw'], (subject) => {
522
- const { error, result } = (0, assertion_util_js_1.trapError)(subject);
523
- if (error === undefined) {
524
- return {
525
- message: `Expected function to throw, but it fulfilled with ${(0, node_util_1.inspect)(result)}`,
526
- };
527
- }
528
- });
529
- /**
530
- * Assertion for testing if a function throws an error of a specific type.
531
- *
532
- * @example
533
- *
534
- * ```typescript
535
- * expect(
536
- * () => {
537
- * throw new TypeError('wrong type');
538
- * },
539
- * 'to throw a',
540
- * TypeError,
541
- * ); // passes
542
- * expect(
543
- * () => {
544
- * throw new Error('oops');
545
- * },
546
- * 'to throw an',
547
- * TypeError,
548
- * ); // fails
549
- * ```
550
- *
551
- * @group Parametric Assertions (Sync)
552
- */
553
- exports.functionThrowsTypeAssertion = (0, create_js_1.createAssertion)([schema_js_1.FunctionSchema, ['to throw a', 'to throw an'], schema_js_1.ConstructibleSchema], (subject, ctor) => {
554
- const { error, result } = (0, assertion_util_js_1.trapError)(subject);
555
- if (error === undefined) {
556
- return {
557
- message: `Expected function to throw, but fulfilled with ${(0, node_util_1.inspect)(result)}`,
558
- };
559
- }
560
- if (!(0, guards_js_1.isA)(error, ctor)) {
561
- if ((0, guards_js_1.isNonNullObject)(error)) {
562
- const err = error;
563
- return {
564
- actual: err.constructor.name,
565
- expected: ctor.name,
566
- message: `Expected function to throw with an instance of ${ctor.name}, but it threw with a ${err.constructor.name}`,
567
- };
568
- }
569
- return {
570
- actual: typeof error,
571
- expected: ctor.name,
572
- message: `Expected function to throw with an instance of ${ctor.name}, but it threw a value of type ${typeof error}: ${(0, node_util_1.inspect)(error)}`,
573
- };
574
- }
575
- });
576
- /**
577
- * Assertion for testing if a function throws an error matching specific
578
- * criteria.
579
- *
580
- * @example
581
- *
582
- * ```typescript
583
- * expect(
584
- * () => {
585
- * throw new Error('oops');
586
- * },
587
- * 'to throw',
588
- * 'oops',
589
- * ); // passes
590
- * expect(
591
- * () => {
592
- * throw new Error('fail');
593
- * },
594
- * 'to throw',
595
- * /error/i,
596
- * ); // passes
597
- * expect(
598
- * () => {
599
- * throw new Error('oops');
600
- * },
601
- * 'to throw',
602
- * { message: 'oops' },
603
- * ); // passes
604
- * ```
605
- *
606
- * @group Parametric Assertions (Sync)
607
- */
608
- exports.functionThrowsSatisfyingAssertion = (0, create_js_1.createAssertion)([schema_js_1.FunctionSchema, ['to throw', 'to throw error satisfying'], schema_js_1.UnknownSchema], (subject, param) => {
609
- const { error } = (0, assertion_util_js_1.trapError)(subject);
610
- if (error === undefined) {
611
- return {
612
- message: 'Expected function to throw, but it did not',
613
- };
614
- }
615
- if ((0, guards_js_1.isString)(param)) {
616
- return {
617
- schema: (0, schema_js_1.createErrorMessageSchema)(param),
618
- subject: error,
619
- };
620
- }
621
- else if ((0, guards_js_1.isA)(param, RegExp)) {
622
- return {
623
- schema: (0, schema_js_1.createErrorMessageRegexSchema)(param),
624
- subject: error,
625
- };
626
- }
627
- else {
628
- const schema = (0, value_to_schema_js_1.valueToSchema)(param, value_to_schema_js_1.valueToSchemaOptionsForSatisfies);
629
- return { schema, subject: error };
630
- }
631
- });
632
- /**
633
- * Assertion for testing if a function throws an error of a specific type that
634
- * also matches criteria.
635
- *
636
- * @example
637
- *
638
- * ```typescript
639
- * expect(
640
- * () => {
641
- * throw new TypeError('wrong type');
642
- * },
643
- * 'to throw a',
644
- * TypeError,
645
- * 'satisfying',
646
- * { message: 'wrong type' },
647
- * ); // passes
648
- * expect(
649
- * () => {
650
- * throw new Error('oops');
651
- * },
652
- * 'to throw an',
653
- * TypeError,
654
- * 'satisfying',
655
- * /type/,
656
- * ); // fails
657
- * ```
658
- *
659
- * @group Parametric Assertions (Sync)
660
- */
661
- exports.functionThrowsTypeSatisfyingAssertion = (0, create_js_1.createAssertion)([
662
- schema_js_1.FunctionSchema,
663
- ['to throw a', 'to throw an'],
664
- schema_js_1.ConstructibleSchema,
665
- 'satisfying',
666
- schema_js_1.UnknownSchema,
667
- ], (subject, ctor, param) => {
668
- const { error, result } = (0, assertion_util_js_1.trapError)(subject);
669
- if (error === undefined) {
670
- return {
671
- message: `Expected function to throw, but it fulfilled with ${(0, node_util_1.inspect)(result)}`,
672
- };
673
- }
674
- if (!(0, guards_js_1.isA)(error, ctor)) {
675
- return {
676
- message: (0, guards_js_1.isError)(error)
677
- ? `Expected function to throw an instance of ${ctor.name}, but it threw ${error.constructor.name}`
678
- : `Expected function to throw an instance of ${ctor.name}, but it threw a non-object value: ${(0, node_util_1.inspect)(error)}`,
679
- };
680
- }
681
- let schema;
682
- if ((0, guards_js_1.isString)(param)) {
683
- schema = (0, schema_js_1.createErrorMessageSchema)(param);
684
- }
685
- else if ((0, guards_js_1.isA)(param, RegExp)) {
686
- schema = (0, schema_js_1.createErrorMessageRegexSchema)(param);
687
- }
688
- else {
689
- schema = (0, value_to_schema_js_1.valueToSchema)(param, value_to_schema_js_1.valueToSchemaOptionsForSatisfies);
690
- }
691
- return {
692
- schema,
693
- subject: error,
694
- };
695
- });
696
- /**
697
- * Assertion for testing if a string includes/contains another string.
698
- *
699
- * @example
700
- *
701
- * ```typescript
702
- * expect('hello world', 'includes', 'world'); // passes
703
- * expect('hello world', 'contains', 'foo'); // fails
704
- * expect('hello world', 'to include', 'hello'); // passes
705
- * expect('hello world', 'to contain', 'bar'); // fails
706
- * ```
707
- *
708
- * @group Parametric Assertions (Sync)
709
- */
710
- exports.stringIncludesAssertion = (0, create_js_1.createAssertion)([
711
- schema_js_1.StringSchema,
712
- ['includes', 'contains', 'to include', 'to contain'],
713
- schema_js_1.StringSchema,
714
- ], (subject, expected) => {
715
- if (!subject.includes(expected)) {
716
- return {
717
- message: `Expected "${subject}" to include "${expected}"`,
718
- };
719
- }
720
- });
721
- /**
722
- * Assertion for testing if a string matches a regular expression.
723
- *
724
- * @example
725
- *
726
- * ```typescript
727
- * expect('hello123', 'to match', /\d+/); // passes
728
- * expect('hello', 'to match', /\d+/); // fails
729
- * ```
730
- *
731
- * @group Parametric Assertions (Sync)
732
- */
733
- exports.stringMatchesAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to match', schema_js_1.RegExpSchema], (subject, regex) => regex.test(subject));
734
- /**
735
- * Assertion for testing if a string has a specific length.
736
- *
737
- * @example
738
- *
739
- * ```typescript
740
- * expect('hello', 'to have length', 5); // passes
741
- * expect('hi', 'to have length', 5); // fails
742
- * ```
743
- *
744
- * @group Parametric Assertions (Sync)
745
- * @bupkisAnchor string-to-have-length
746
- * @bupkisAssertionCategory strings
747
- */
748
- exports.stringLengthAssertion = (0, create_js_1.createAssertion)([schema_js_1.StringSchema, 'to have length', schema_js_1.NonNegativeIntegerSchema],
749
- // StringSchema.length() produces a ZodError with a string diff (e.g., "hel"
750
- // vs "hello") rather than comparing numeric lengths, which is confusing
751
- (subject, expectedLength) => {
752
- if (subject.length !== expectedLength) {
753
- return {
754
- actual: subject.length,
755
- expected: expectedLength,
756
- message: `Expected string to have length ${expectedLength}, but it has length ${subject.length}`,
757
- };
758
- }
759
- });
760
- /**
761
- * Assertion for testing if a value satisfies a pattern or shape.
762
- *
763
- * Works with any value type: primitives, objects, arrays, or cross-type checks.
764
- * Uses partial matching semantics - extra properties are allowed in objects.
765
- *
766
- * @example
767
- *
768
- * ```typescript
769
- * // Primitives
770
- * expect(42, 'to satisfy', 42); // passes
771
- * expect('hello', 'satisfies', 'hello'); // passes
772
- *
773
- * // Objects (partial matching)
774
- * expect({ name: 'John', age: 30 }, 'to satisfy', { name: 'John' }); // passes
775
- * expect({ name: 'John' }, 'to be like', { name: 'John', age: 30 }); // fails
776
- *
777
- * // Arrays
778
- * expect([1, 2, 3], 'to satisfy', [1, 2, 3]); // passes
779
- *
780
- * // Cross-type satisfaction
781
- * expect([1, 2, 3], 'to satisfy', { length: 3 }); // passes
782
- * ```
783
- *
784
- * @group Parametric Assertions (Sync)
785
- * @bupkisAnchor unknown-to-satisfy-any
786
- * @bupkisAssertionCategory equality
787
- */
788
- exports.satisfiesAssertion = (0, create_js_1.createAssertion)([['to satisfy', 'to be like', 'satisfies'], schema_js_1.UnknownSchema], (_subject, shape) => (0, value_to_schema_js_1.valueToSchema)(shape, value_to_schema_js_1.valueToSchemaOptionsForSatisfies));
789
- /**
790
- * Memoizes {@link createInstanceOfSchema}
791
- */
792
- const createInstanceOfSchemaCache = new WeakMap();
793
- /**
794
- * @function
795
- */
796
- const createInstanceOfSchema = (ctor) => {
797
- const cached = createInstanceOfSchemaCache.get(ctor);
798
- if (cached) {
799
- return cached;
800
- }
801
- const schema = zod_1.z.instanceof(ctor);
802
- createInstanceOfSchemaCache.set(ctor, schema);
803
- return schema;
804
- };
805
- //# sourceMappingURL=sync-parametric.js.map