@tapjs/asserts
Advanced tools
Comparing version 0.0.0-12 to 0.0.0-13
@@ -35,2 +35,4 @@ /// <reference types="node" resolution-mode="require"/> | ||
* Verify that the value is truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -40,2 +42,4 @@ ok(obj: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is not truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -45,2 +49,4 @@ notOk(obj: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the values are equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -50,2 +56,4 @@ equal<T extends unknown>(found: any, wanted: T, ...[msg, extra]: MessageExtra): found is T; | ||
* Verify that the values are not equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -60,2 +68,4 @@ not(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* object's constructor. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -65,2 +75,4 @@ type(obj: any, klass: string | Function, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -70,2 +82,4 @@ same(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is not loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -75,2 +89,4 @@ notSame(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is strictly equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -81,2 +97,4 @@ strictSame<T extends unknown>(found: any, wanted: T, ...[msg, extra]: MessageExtra): found is T; | ||
* pattern object | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -87,2 +105,4 @@ strictNotSame(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -93,2 +113,4 @@ has(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* in the pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -99,2 +121,4 @@ notHas(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* pattern, matching strictly. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -108,2 +132,4 @@ hasStrict(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* or if they do not match the same type. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -113,2 +139,4 @@ notHasStrict(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value matches the pattern provided | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -118,2 +146,4 @@ match(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value does NOT match the pattern provided. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -124,2 +154,4 @@ notMatch(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -130,2 +162,4 @@ matchOnly(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -136,2 +170,4 @@ notMatchOnly(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -142,2 +178,4 @@ matchOnlyStrict(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -155,2 +193,4 @@ notMatchOnlyStrict(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* ``` | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -161,2 +201,4 @@ matchStrict(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* type coercion. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -167,2 +209,4 @@ notMatchStrict(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -173,2 +217,4 @@ hasProp<T extends {}>(found: T, wanted: string | number | symbol, ...[msg, extra]: MessageExtra): boolean; | ||
* Object#hasOwnProperty | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -179,2 +225,4 @@ hasOwnProp<T extends {}>(found: T, wanted: string | number | symbol, ...[msg, extra]: MessageExtra): boolean; | ||
* list, anywhere in its prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -185,2 +233,4 @@ hasProps<T extends {}>(found: T, wanted: Iterable<string | number | symbol>, ...[msg, extra]: MessageExtra): boolean; | ||
* `wanted` list, using Object#hasOwnProperties() | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -191,2 +241,4 @@ hasOwnProps<T extends {}>(found: T, wanted: Iterable<string | number | symbol>, ...[msg, extra]: MessageExtra): boolean; | ||
* `wanted` list, using Object#hasOwnProperties(), and no others | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -200,2 +252,4 @@ hasOwnPropsOnly<T extends {}>(found: T, wanted: Iterable<string | number | symbol>, ...[msg, extra]: MessageExtra): boolean; | ||
* Returns false on failure, or the error object thrown on success | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -207,2 +261,4 @@ throws(fn: Function | (() => any), ...[wanted, msg, extra]: ThrowsArgs): boolean | Error; | ||
* passing status, like other assertions. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -214,2 +270,4 @@ doesNotThrow(fn: Function | (() => any), ...[msg, extra]: MessageExtra): boolean | Error; | ||
* as skip/todo. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -221,2 +279,4 @@ rejects<T extends any = any>(fnOrPromise: (() => Promise<T>) | Promise<T>, ...[wanted, msg, extra]: ThrowsArgs): Promise<boolean | Error>; | ||
* failure is accepted by by being marked todo or skip | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -230,2 +290,4 @@ resolves<T extends any = any>(fnOrPromise: Promise<T> | (() => Promise<T>), ...[msg, extra]: MessageExtra): Promise<boolean | Error>; | ||
* assertion passes by being marked todo/skip. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -240,6 +302,9 @@ resolveMatch<T extends any = any>(fnOrPromise: Promise<T> | (() => Promise<T>), wanted: any, ...[msg, extra]: MessageExtra): Promise<boolean>; | ||
* reasonably confident that it will fire. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
emits(emitter: EventEmitter | EventTarget, event: string, ...[msg, extra]: MessageExtra): Promise<void>; | ||
error(er: unknown, ...[msg, extra]: MessageExtra): boolean; | ||
} | ||
export declare const plugin: TapPlugin<Assertions, AssertOptions>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -79,2 +79,4 @@ "use strict"; | ||
* Verify that the value is truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -89,2 +91,4 @@ ok(obj, ...[msg, extra]) { | ||
* Verify that the value is not truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -99,2 +103,4 @@ notOk(obj, ...[msg, extra]) { | ||
* Verify that the values are equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -128,2 +134,4 @@ equal(found, wanted, ...[msg, extra]) { | ||
* Verify that the values are not equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -151,2 +159,4 @@ not(found, doNotWant, ...[msg, extra]) { | ||
* object's constructor. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -202,2 +212,4 @@ type(obj, klass, ...[msg, extra]) { | ||
* Verify that the value is loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -216,2 +228,4 @@ same(found, wanted, ...[msg, extra]) { | ||
* Verify that the value is not loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -230,2 +244,4 @@ notSame(found, doNotWant, ...[msg, extra]) { | ||
* Verify that the value is strictly equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -245,2 +261,4 @@ strictSame(found, wanted, ...[msg, extra]) { | ||
* pattern object | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -260,2 +278,4 @@ strictNotSame(found, doNotWant, ...[msg, extra]) { | ||
* pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -275,2 +295,4 @@ has(found, wanted, ...[msg, extra]) { | ||
* in the pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -290,2 +312,4 @@ notHas(found, doNotWant, ...[msg, extra]) { | ||
* pattern, matching strictly. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -308,2 +332,4 @@ hasStrict(found, wanted, ...[msg, extra]) { | ||
* or if they do not match the same type. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -322,2 +348,4 @@ notHasStrict(found, doNotWant, ...[msg, extra]) { | ||
* Verify that the value matches the pattern provided | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -336,2 +364,4 @@ match(found, wanted, ...[msg, extra]) { | ||
* Verify that the value does NOT match the pattern provided. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -351,2 +381,4 @@ notMatch(found, doNotWant, ...[msg, extra]) { | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -366,2 +398,4 @@ matchOnly(found, wanted, ...[msg, extra]) { | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -381,2 +415,4 @@ notMatchOnly(found, doNotWant, ...[msg, extra]) { | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -396,2 +432,4 @@ matchOnlyStrict(found, wanted, ...[msg, extra]) { | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -418,2 +456,4 @@ notMatchOnlyStrict(found, doNotWant, ...[msg, extra]) { | ||
* ``` | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -433,2 +473,4 @@ matchStrict(found, wanted, ...[msg, extra]) { | ||
* type coercion. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -448,2 +490,4 @@ notMatchStrict(found, doNotWant, ...[msg, extra]) { | ||
* prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -471,2 +515,4 @@ hasProp(found, wanted, ...[msg, extra]) { | ||
* Object#hasOwnProperty | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -494,2 +540,4 @@ hasOwnProp(found, wanted, ...[msg, extra]) { | ||
* list, anywhere in its prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -524,2 +572,4 @@ hasProps(found, wanted, ...[msg, extra]) { | ||
* `wanted` list, using Object#hasOwnProperties() | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -554,2 +604,4 @@ hasOwnProps(found, wanted, ...[msg, extra]) { | ||
* `wanted` list, using Object#hasOwnProperties(), and no others | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -593,2 +645,4 @@ hasOwnPropsOnly(found, wanted, ...[msg, extra]) { | ||
* Returns false on failure, or the error object thrown on success | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -622,2 +676,4 @@ throws(fn, ...[wanted, msg, extra]) { | ||
* passing status, like other assertions. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -633,3 +689,7 @@ doesNotThrow(fn, ...[msg, extra]) { | ||
catch (er) { | ||
return this.#t.fail(...me) && er; | ||
// pull the errorOrigin from the thrown error, if possible | ||
const res = er !== undefined && er !== null | ||
? this.error(er, ...me) | ||
: this.#t.fail(...me); | ||
return (res && er) || res; | ||
} | ||
@@ -641,2 +701,4 @@ } | ||
* as skip/todo. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -646,2 +708,4 @@ async rejects(fnOrPromise, ...[wanted, msg, extra]) { | ||
const [w, m, e] = (0, normalize_throws_args_js_1.normalizeThrowsArgs)('expected to reject', args); | ||
this.#t.currentAssert = this.#t.t.rejects; | ||
e.at = e.at || stack.at(this.#t.currentAssert); | ||
let p; | ||
@@ -658,7 +722,6 @@ try { | ||
if (!(0, is_actual_promise_1.isPromise)(p)) { | ||
return this.#t.fail('no promise or async function provided to t.rejects'); | ||
return this.#t.fail('no promise or async function provided to t.rejects', e); | ||
} | ||
const d = new trivial_deferred_1.Deferred(); | ||
this.#t.waitOn(d.promise); | ||
this.#t.currentAssert = this.#t.t.rejects; | ||
try { | ||
@@ -680,3 +743,4 @@ await p; | ||
? this.match(isRegExp(w) ? er.message : er, w, m, e) | ||
: this.#t.pass(m, e)) && er); | ||
: this.#t.pass(m, e)) && | ||
(er || true)); | ||
} | ||
@@ -689,2 +753,4 @@ return d.promise; | ||
* failure is accepted by by being marked todo or skip | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -695,2 +761,3 @@ async resolves(fnOrPromise, ...[msg, extra]) { | ||
const me = (0, core_1.normalizeMessageExtra)('expected to resolve', args); | ||
me[1].at = me[1].at || stack.at(this.#t.currentAssert); | ||
let p; | ||
@@ -707,3 +774,3 @@ try { | ||
if (!(0, is_actual_promise_1.isPromise)(p)) { | ||
return this.#t.fail('no promise or async function provided to t.resolves'); | ||
return this.#t.fail('no promise or async function provided to t.resolves', me[1]); | ||
} | ||
@@ -717,3 +784,7 @@ const d = new trivial_deferred_1.Deferred(); | ||
catch (er) { | ||
d.resolve(this.#t.fail(...me) || er); | ||
// pull the errorOrigin from the thrown error, if possible | ||
const res = er !== undefined && er !== null | ||
? this.error(er, ...me) | ||
: this.#t.fail(...me); | ||
d.resolve((res && er) || res); | ||
} | ||
@@ -728,2 +799,4 @@ return d.promise; | ||
* assertion passes by being marked todo/skip. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -733,2 +806,4 @@ async resolveMatch(fnOrPromise, wanted, ...[msg, extra]) { | ||
const me = (0, core_1.normalizeMessageExtra)('expected to resolve and match provided pattern', args); | ||
this.#t.currentAssert = this.#t.t.resolveMatch; | ||
me[1].at = me[1].at || stack.at(this.#t.currentAssert); | ||
let p; | ||
@@ -745,7 +820,6 @@ try { | ||
if (!(0, is_actual_promise_1.isPromise)(p)) { | ||
return this.#t.fail('no promise or async function provided to t.resolveMatch'); | ||
return this.#t.fail('no promise or async function provided to t.resolveMatch', me[1]); | ||
} | ||
const d = new trivial_deferred_1.Deferred(); | ||
this.#t.waitOn(d.promise); | ||
this.#t.currentAssert = this.#t.t.resolveMatch; | ||
try { | ||
@@ -755,3 +829,6 @@ d.resolve(this.match(await p, wanted, ...me)); | ||
catch (er) { | ||
d.resolve(this.#t.fail(...me)); | ||
// pull the errorOrigin from the thrown error, if possible | ||
d.resolve(er !== undefined && er !== null | ||
? this.error(er, ...me) | ||
: this.#t.fail(...me)); | ||
} | ||
@@ -768,2 +845,4 @@ return d.promise; | ||
* reasonably confident that it will fire. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -804,2 +883,30 @@ emits(emitter, event, ...[msg, extra]) { | ||
} | ||
error(er, ...[msg, extra]) { | ||
const args = [msg, extra]; | ||
const me = (0, core_1.normalizeMessageExtra)(`should not error`, args); | ||
this.#t.currentAssert = this.#t.t.error; | ||
if (er === undefined || er === null) | ||
return this.#t.pass(...me); | ||
if (!(er instanceof Error)) { | ||
return this.#t.fail(...(0, core_1.normalizeMessageExtra)('non-Error error encountered', [ | ||
msg, | ||
{ ...me[1], found: er }, | ||
])); | ||
} | ||
// ok, we got an error, that's a problem | ||
me[1].message = er?.message || me[0]; | ||
const { at, stack } = me[1]; | ||
const ex = (0, core_1.extraFromError)(er, me[1]); | ||
// put the error's origin on the object, but let the normal | ||
// diags parsing show us where the failed assertion happened, | ||
// or respect the at/stack added by another caller. | ||
ex.errorOrigin = { | ||
at: ex.at, | ||
stack: ex.stack, | ||
}; | ||
ex.at = at; | ||
ex.stack = stack; | ||
// always going to have *something* here. | ||
return this.#t.fail(ex.message, ex); | ||
} | ||
} | ||
@@ -806,0 +913,0 @@ exports.Assertions = Assertions; |
@@ -35,2 +35,4 @@ /// <reference types="node" resolution-mode="require"/> | ||
* Verify that the value is truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -40,2 +42,4 @@ ok(obj: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is not truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -45,2 +49,4 @@ notOk(obj: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the values are equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -50,2 +56,4 @@ equal<T extends unknown>(found: any, wanted: T, ...[msg, extra]: MessageExtra): found is T; | ||
* Verify that the values are not equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -60,2 +68,4 @@ not(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* object's constructor. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -65,2 +75,4 @@ type(obj: any, klass: string | Function, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -70,2 +82,4 @@ same(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is not loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -75,2 +89,4 @@ notSame(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value is strictly equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -81,2 +97,4 @@ strictSame<T extends unknown>(found: any, wanted: T, ...[msg, extra]: MessageExtra): found is T; | ||
* pattern object | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -87,2 +105,4 @@ strictNotSame(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -93,2 +113,4 @@ has(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* in the pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -99,2 +121,4 @@ notHas(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* pattern, matching strictly. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -108,2 +132,4 @@ hasStrict(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* or if they do not match the same type. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -113,2 +139,4 @@ notHasStrict(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value matches the pattern provided | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -118,2 +146,4 @@ match(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* Verify that the value does NOT match the pattern provided. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -124,2 +154,4 @@ notMatch(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -130,2 +162,4 @@ matchOnly(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -136,2 +170,4 @@ notMatchOnly(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -142,2 +178,4 @@ matchOnlyStrict(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -155,2 +193,4 @@ notMatchOnlyStrict(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* ``` | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -161,2 +201,4 @@ matchStrict(found: any, wanted: any, ...[msg, extra]: MessageExtra): boolean; | ||
* type coercion. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -167,2 +209,4 @@ notMatchStrict(found: any, doNotWant: any, ...[msg, extra]: MessageExtra): boolean; | ||
* prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -173,2 +217,4 @@ hasProp<T extends {}>(found: T, wanted: string | number | symbol, ...[msg, extra]: MessageExtra): boolean; | ||
* Object#hasOwnProperty | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -179,2 +225,4 @@ hasOwnProp<T extends {}>(found: T, wanted: string | number | symbol, ...[msg, extra]: MessageExtra): boolean; | ||
* list, anywhere in its prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -185,2 +233,4 @@ hasProps<T extends {}>(found: T, wanted: Iterable<string | number | symbol>, ...[msg, extra]: MessageExtra): boolean; | ||
* `wanted` list, using Object#hasOwnProperties() | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -191,2 +241,4 @@ hasOwnProps<T extends {}>(found: T, wanted: Iterable<string | number | symbol>, ...[msg, extra]: MessageExtra): boolean; | ||
* `wanted` list, using Object#hasOwnProperties(), and no others | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -200,2 +252,4 @@ hasOwnPropsOnly<T extends {}>(found: T, wanted: Iterable<string | number | symbol>, ...[msg, extra]: MessageExtra): boolean; | ||
* Returns false on failure, or the error object thrown on success | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -207,2 +261,4 @@ throws(fn: Function | (() => any), ...[wanted, msg, extra]: ThrowsArgs): boolean | Error; | ||
* passing status, like other assertions. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -214,2 +270,4 @@ doesNotThrow(fn: Function | (() => any), ...[msg, extra]: MessageExtra): boolean | Error; | ||
* as skip/todo. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -221,2 +279,4 @@ rejects<T extends any = any>(fnOrPromise: (() => Promise<T>) | Promise<T>, ...[wanted, msg, extra]: ThrowsArgs): Promise<boolean | Error>; | ||
* failure is accepted by by being marked todo or skip | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -230,2 +290,4 @@ resolves<T extends any = any>(fnOrPromise: Promise<T> | (() => Promise<T>), ...[msg, extra]: MessageExtra): Promise<boolean | Error>; | ||
* assertion passes by being marked todo/skip. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -240,6 +302,9 @@ resolveMatch<T extends any = any>(fnOrPromise: Promise<T> | (() => Promise<T>), wanted: any, ...[msg, extra]: MessageExtra): Promise<boolean>; | ||
* reasonably confident that it will fire. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
emits(emitter: EventEmitter | EventTarget, event: string, ...[msg, extra]: MessageExtra): Promise<void>; | ||
error(er: unknown, ...[msg, extra]: MessageExtra): boolean; | ||
} | ||
export declare const plugin: TapPlugin<Assertions, AssertOptions>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { normalizeMessageExtra, } from '@tapjs/core'; | ||
import { extraFromError, normalizeMessageExtra, } from '@tapjs/core'; | ||
import * as stack from '@tapjs/stack'; | ||
@@ -50,2 +50,4 @@ import EventEmitter from 'events'; | ||
* Verify that the value is truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -60,2 +62,4 @@ ok(obj, ...[msg, extra]) { | ||
* Verify that the value is not truthy | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -70,2 +74,4 @@ notOk(obj, ...[msg, extra]) { | ||
* Verify that the values are equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -99,2 +105,4 @@ equal(found, wanted, ...[msg, extra]) { | ||
* Verify that the values are not equal | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -122,2 +130,4 @@ not(found, doNotWant, ...[msg, extra]) { | ||
* object's constructor. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -173,2 +183,4 @@ type(obj, klass, ...[msg, extra]) { | ||
* Verify that the value is loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -187,2 +199,4 @@ same(found, wanted, ...[msg, extra]) { | ||
* Verify that the value is not loosely equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -201,2 +215,4 @@ notSame(found, doNotWant, ...[msg, extra]) { | ||
* Verify that the value is strictly equivalent to the supplied pattern | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -216,2 +232,4 @@ strictSame(found, wanted, ...[msg, extra]) { | ||
* pattern object | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -231,2 +249,4 @@ strictNotSame(found, doNotWant, ...[msg, extra]) { | ||
* pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -246,2 +266,4 @@ has(found, wanted, ...[msg, extra]) { | ||
* in the pattern, matching loosely. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -261,2 +283,4 @@ notHas(found, doNotWant, ...[msg, extra]) { | ||
* pattern, matching strictly. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -279,2 +303,4 @@ hasStrict(found, wanted, ...[msg, extra]) { | ||
* or if they do not match the same type. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -293,2 +319,4 @@ notHasStrict(found, doNotWant, ...[msg, extra]) { | ||
* Verify that the value matches the pattern provided | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -307,2 +335,4 @@ match(found, wanted, ...[msg, extra]) { | ||
* Verify that the value does NOT match the pattern provided. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -322,2 +352,4 @@ notMatch(found, doNotWant, ...[msg, extra]) { | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -337,2 +369,4 @@ matchOnly(found, wanted, ...[msg, extra]) { | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -352,2 +386,4 @@ notMatchOnly(found, doNotWant, ...[msg, extra]) { | ||
* extra properties. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -367,2 +403,4 @@ matchOnlyStrict(found, wanted, ...[msg, extra]) { | ||
* extra properties. Ie, it might either not match, or have extra props. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -389,2 +427,4 @@ notMatchOnlyStrict(found, doNotWant, ...[msg, extra]) { | ||
* ``` | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -404,2 +444,4 @@ matchStrict(found, wanted, ...[msg, extra]) { | ||
* type coercion. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -419,2 +461,4 @@ notMatchStrict(found, doNotWant, ...[msg, extra]) { | ||
* prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -442,2 +486,4 @@ hasProp(found, wanted, ...[msg, extra]) { | ||
* Object#hasOwnProperty | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -465,2 +511,4 @@ hasOwnProp(found, wanted, ...[msg, extra]) { | ||
* list, anywhere in its prototype chain. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -495,2 +543,4 @@ hasProps(found, wanted, ...[msg, extra]) { | ||
* `wanted` list, using Object#hasOwnProperties() | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -525,2 +575,4 @@ hasOwnProps(found, wanted, ...[msg, extra]) { | ||
* `wanted` list, using Object#hasOwnProperties(), and no others | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -564,2 +616,4 @@ hasOwnPropsOnly(found, wanted, ...[msg, extra]) { | ||
* Returns false on failure, or the error object thrown on success | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -593,2 +647,4 @@ throws(fn, ...[wanted, msg, extra]) { | ||
* passing status, like other assertions. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -604,3 +660,7 @@ doesNotThrow(fn, ...[msg, extra]) { | ||
catch (er) { | ||
return this.#t.fail(...me) && er; | ||
// pull the errorOrigin from the thrown error, if possible | ||
const res = er !== undefined && er !== null | ||
? this.error(er, ...me) | ||
: this.#t.fail(...me); | ||
return (res && er) || res; | ||
} | ||
@@ -612,2 +672,4 @@ } | ||
* as skip/todo. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -617,2 +679,4 @@ async rejects(fnOrPromise, ...[wanted, msg, extra]) { | ||
const [w, m, e] = normalizeThrowsArgs('expected to reject', args); | ||
this.#t.currentAssert = this.#t.t.rejects; | ||
e.at = e.at || stack.at(this.#t.currentAssert); | ||
let p; | ||
@@ -629,7 +693,6 @@ try { | ||
if (!isPromise(p)) { | ||
return this.#t.fail('no promise or async function provided to t.rejects'); | ||
return this.#t.fail('no promise or async function provided to t.rejects', e); | ||
} | ||
const d = new Deferred(); | ||
this.#t.waitOn(d.promise); | ||
this.#t.currentAssert = this.#t.t.rejects; | ||
try { | ||
@@ -651,3 +714,4 @@ await p; | ||
? this.match(isRegExp(w) ? er.message : er, w, m, e) | ||
: this.#t.pass(m, e)) && er); | ||
: this.#t.pass(m, e)) && | ||
(er || true)); | ||
} | ||
@@ -660,2 +724,4 @@ return d.promise; | ||
* failure is accepted by by being marked todo or skip | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -666,2 +732,3 @@ async resolves(fnOrPromise, ...[msg, extra]) { | ||
const me = normalizeMessageExtra('expected to resolve', args); | ||
me[1].at = me[1].at || stack.at(this.#t.currentAssert); | ||
let p; | ||
@@ -678,3 +745,3 @@ try { | ||
if (!isPromise(p)) { | ||
return this.#t.fail('no promise or async function provided to t.resolves'); | ||
return this.#t.fail('no promise or async function provided to t.resolves', me[1]); | ||
} | ||
@@ -688,3 +755,7 @@ const d = new Deferred(); | ||
catch (er) { | ||
d.resolve(this.#t.fail(...me) || er); | ||
// pull the errorOrigin from the thrown error, if possible | ||
const res = er !== undefined && er !== null | ||
? this.error(er, ...me) | ||
: this.#t.fail(...me); | ||
d.resolve((res && er) || res); | ||
} | ||
@@ -699,2 +770,4 @@ return d.promise; | ||
* assertion passes by being marked todo/skip. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -704,2 +777,4 @@ async resolveMatch(fnOrPromise, wanted, ...[msg, extra]) { | ||
const me = normalizeMessageExtra('expected to resolve and match provided pattern', args); | ||
this.#t.currentAssert = this.#t.t.resolveMatch; | ||
me[1].at = me[1].at || stack.at(this.#t.currentAssert); | ||
let p; | ||
@@ -716,7 +791,6 @@ try { | ||
if (!isPromise(p)) { | ||
return this.#t.fail('no promise or async function provided to t.resolveMatch'); | ||
return this.#t.fail('no promise or async function provided to t.resolveMatch', me[1]); | ||
} | ||
const d = new Deferred(); | ||
this.#t.waitOn(d.promise); | ||
this.#t.currentAssert = this.#t.t.resolveMatch; | ||
try { | ||
@@ -726,3 +800,6 @@ d.resolve(this.match(await p, wanted, ...me)); | ||
catch (er) { | ||
d.resolve(this.#t.fail(...me)); | ||
// pull the errorOrigin from the thrown error, if possible | ||
d.resolve(er !== undefined && er !== null | ||
? this.error(er, ...me) | ||
: this.#t.fail(...me)); | ||
} | ||
@@ -739,2 +816,4 @@ return d.promise; | ||
* reasonably confident that it will fire. | ||
* | ||
* @group Assertion Methods | ||
*/ | ||
@@ -775,2 +854,30 @@ emits(emitter, event, ...[msg, extra]) { | ||
} | ||
error(er, ...[msg, extra]) { | ||
const args = [msg, extra]; | ||
const me = normalizeMessageExtra(`should not error`, args); | ||
this.#t.currentAssert = this.#t.t.error; | ||
if (er === undefined || er === null) | ||
return this.#t.pass(...me); | ||
if (!(er instanceof Error)) { | ||
return this.#t.fail(...normalizeMessageExtra('non-Error error encountered', [ | ||
msg, | ||
{ ...me[1], found: er }, | ||
])); | ||
} | ||
// ok, we got an error, that's a problem | ||
me[1].message = er?.message || me[0]; | ||
const { at, stack } = me[1]; | ||
const ex = extraFromError(er, me[1]); | ||
// put the error's origin on the object, but let the normal | ||
// diags parsing show us where the failed assertion happened, | ||
// or respect the at/stack added by another caller. | ||
ex.errorOrigin = { | ||
at: ex.at, | ||
stack: ex.stack, | ||
}; | ||
ex.at = at; | ||
ex.stack = stack; | ||
// always going to have *something* here. | ||
return this.#t.fail(ex.message, ex); | ||
} | ||
} | ||
@@ -777,0 +884,0 @@ const isIterable = (it) => typeof it === 'string' || |
{ | ||
"name": "@tapjs/asserts", | ||
"version": "0.0.0-12", | ||
"version": "0.0.0-13", | ||
"description": "", | ||
@@ -40,3 +40,3 @@ "author": "Isaac Z. Schlueter <i@izs.me> (https://blog.izs.me)", | ||
"peerDependencies": { | ||
"@tapjs/core": "0.0.0-12" | ||
"@tapjs/core": "0.0.0-13" | ||
}, | ||
@@ -43,0 +43,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
228365
2315