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