New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

iko

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iko - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

dist/cjs/snapshot.js

22

dist/cjs/diff.js

@@ -7,12 +7,8 @@ "use strict";

const stringify_1 = require("./stringify");
const NO_DIFF_MESSAGE = rtext_writer_1.richText()
.begin("hint")
.write("Compared values have no visual difference.")
.end("hint")
const NO_DIFF_MESSAGE = stringify_1.errMsg()
.hint("Compared values have no visual difference.")
.compose();
const SIMILAR_MESSAGE = rtext_writer_1.richText()
.begin("hint")
.write("Compared values serialize to the same structure.\n")
.write("Printing internal object structure without calling `toJSON` instead.")
.end("hint")
const SIMILAR_MESSAGE = stringify_1.errMsg()
.hint("Compared values serialize to the same structure.\n")
.hint("Printing internal object structure without calling `toJSON` instead.")
.compose();

@@ -46,3 +42,3 @@ const DIFF_CONTEXT = 5;

while (j < lines.length) {
result.begin("+").write("+ ", stringify_1.highlightTrailingWhitespace(lines[j++]), "\n").end("+");
result.begin("+").write("+ ", stringify_1.hl(lines[j++]), "\n").end("+");
}

@@ -53,3 +49,3 @@ }

while (j < lines.length) {
result.begin("-").write("- ", stringify_1.highlightTrailingWhitespace(lines[j++]), "\n").end("-");
result.begin("-").write("- ", stringify_1.hl(lines[j++]), "\n").end("-");
}

@@ -59,3 +55,3 @@ }

while (j < lines.length) {
result.write(" ", stringify_1.highlightTrailingWhitespace(lines[j++]), "\n");
result.write(" ", stringify_1.hl(lines[j++]), "\n");
}

@@ -109,3 +105,3 @@ }

const line = lines[j];
const highlightedLined = stringify_1.highlightTrailingWhitespace(line);
const highlightedLined = stringify_1.hl(line);
const added = line.charCodeAt(0) === 43; // +

@@ -112,0 +108,0 @@ const removed = line.charCodeAt(0) === 45; // -

@@ -5,8 +5,5 @@ "use strict";

class AssertionError extends Error {
constructor(message, actual, expected, ssf) {
constructor(message, ssf) {
super(message.text);
this.actual = actual;
if (expected !== undefined) {
this.expected = expected;
}
this.$$type = "AssertionError";
if (message.annotations !== null) {

@@ -13,0 +10,0 @@ this.annotations = message.annotations;

@@ -5,10 +5,17 @@ "use strict";

exports.AssertionError = error_1.AssertionError;
var matcher_1 = require("./matcher");
exports.Matcher = matcher_1.Matcher;
exports.m = matcher_1.m;
const diff_1 = require("./diff");
var stringify_1 = require("./stringify");
exports.ErrorMessageWriter = stringify_1.ErrorMessageWriter;
exports.errMsg = stringify_1.errMsg;
exports.r = stringify_1.r;
exports.e = stringify_1.e;
exports.hl = stringify_1.hl;
exports.stringify = stringify_1.stringify;
var diff_1 = require("./diff");
exports.diff = diff_1.diff;
const rtext_writer_1 = require("rtext-writer");
const error_2 = require("./error");
const stringify_1 = require("./stringify");
const matcher_2 = require("./matcher");
const diff_2 = require("./diff");
const stringify_2 = require("./stringify");
const snapshot_1 = require("./snapshot");
const lodash_1 = require("lodash");
class Assertion {

@@ -19,3 +26,3 @@ constructor(obj) {

toSnapshot() {
return this.obj;
return this.obj.toString();
}

@@ -25,3 +32,3 @@ assert(expr, message, expected, actual) {

if (pass === false) {
throw new error_2.AssertionError(message(expected, actual), actual, expected, this.assert);
throw new error_2.AssertionError(message(expected, actual), this.assert);
}

@@ -34,7 +41,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeFalsy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, false, this.toBeFalsy);
const message = stringify_2.errMsg()
.matcherHint("toBeFalsy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeFalsy);
}

@@ -47,7 +54,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeTruthy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeTruthy);
const message = stringify_2.errMsg()
.matcherHint("toBeTruthy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeTruthy);
}

@@ -61,17 +68,13 @@ return this;

if (!pass) {
const diffText = diff_1.diff(expected, received);
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBe"))
.write("Expected value to be (strict equality ===):\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
const diffText = diff_2.diff(expected, received);
const message = stringify_2.errMsg()
.matcherHint("toBe")
.info("Expected value to be (strict equality ===):\n")
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
if (diffText !== null) {
message
.begin("diff")
.write("\n", "Difference:\n\n")
.write(diffText)
.end("diff");
message.diff("\nDifference:\n\n", diffText);
}
throw new error_2.AssertionError(message.compose(), received, expected, this.toBe);
throw new error_2.AssertionError(message.compose(), this.toBe);
}

@@ -85,9 +88,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBe"))
.write("Expected value not to be (strict inequality !==):\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, expected, this.toBe);
const message = stringify_2.errMsg()
.matcherHint("notToBe")
.info("Expected value not to be (strict inequality !==):\n")
.info(" ", stringify_2.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), this.toBe);
}

@@ -100,7 +101,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeNull", "received", ""))
.write("Expected value to be null, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeNull);
const message = stringify_2.errMsg()
.matcherHint("toBeNull", "received", "")
.info("Expected value to be null, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeNull);
}

@@ -113,6 +114,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeNull", "received", ""))
.write("Expected value not to be null\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToBeNull);
const message = stringify_2.errMsg()
.matcherHint("notToBeNull", "received", "")
.info("Expected value not to be null\n");
throw new error_2.AssertionError(message.compose(), this.notToBeNull);
}

@@ -125,7 +126,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeUndefined", "received", ""))
.write("Expected value to be undefined, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeUndefined);
const message = stringify_2.errMsg()
.matcherHint("toBeUndefined", "received", "")
.info("Expected value to be undefined, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeUndefined);
}

@@ -138,6 +139,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeUndefined", "received", ""))
.write("Expected value not to be undefined\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToBeUndefined);
const message = stringify_2.errMsg()
.matcherHint("notToBeUndefined", "received", "")
.info("Expected value not to be undefined\n");
throw new error_2.AssertionError(message.compose(), this.notToBeUndefined);
}

@@ -150,7 +151,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeObject", "received", ""))
.write("Expected value to be an object, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeObject);
const message = stringify_2.errMsg()
.matcherHint("toBeObject", "received", "")
.info("Expected value to be an object, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeObject);
}

@@ -163,7 +164,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeArray", "received", ""))
.write("Expected value to be an array, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeArray);
const message = stringify_2.errMsg()
.matcherHint("toBeArray", "received", "")
.info("Expected value to be an array, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeArray);
}

@@ -176,7 +177,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeBoolean", "received", ""))
.write("Expected value to be a boolean, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeBoolean);
const message = stringify_2.errMsg()
.matcherHint("toBeBoolean", "received", "")
.info("Expected value to be a boolean, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeBoolean);
}

@@ -189,7 +190,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeNumber", "received", ""))
.write("Expected value to be a number, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeNumber);
const message = stringify_2.errMsg()
.matcherHint("toBeNumber", "received", "")
.info("Expected value to be a number, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeNumber);
}

@@ -202,7 +203,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeString", "received", ""))
.write("Expected value to be a string, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeString);
const message = stringify_2.errMsg()
.matcherHint("toBeString", "received", "")
.info("Expected value to be a string, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeString);
}

@@ -215,7 +216,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeFunction", "received", ""))
.write("Expected value to be a function, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeFunction);
const message = stringify_2.errMsg()
.matcherHint("toBeFunction", "received", "")
.info("Expected value to be a function, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeFunction);
}

@@ -228,7 +229,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeSymbol", "received", ""))
.write("Expected value to be a symbol, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeSymbol);
const message = stringify_2.errMsg()
.matcherHint("toBeSymbol", "received", "")
.info("Expected value to be a symbol, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeSymbol);
}

@@ -241,7 +242,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeDate", "received", ""))
.write("Expected value to be a Date, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeDate);
const message = stringify_2.errMsg()
.matcherHint("toBeDate", "received", "")
.info("Expected value to be a Date, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeDate);
}

@@ -254,7 +255,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeRegExp", "received", ""))
.write("Expected value to be a RegExp, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeRegExp);
const message = stringify_2.errMsg()
.matcherHint("toBeRegExp", "received", "")
.info("Expected value to be a RegExp, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeRegExp);
}

@@ -267,7 +268,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeError", "received", ""))
.write("Expected value to be an Error, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeError);
const message = stringify_2.errMsg()
.matcherHint("toBeError", "received", "")
.info("Expected value to be an Error, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeError);
}

@@ -280,7 +281,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeMap", "received", ""))
.write("Expected value to be a Map, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeMap);
const message = stringify_2.errMsg()
.matcherHint("toBeMap", "received", "")
.info("Expected value to be a Map, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeMap);
}

@@ -293,7 +294,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeWeakMap", "received", ""))
.write("Expected value to be a WeakMap, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeWeakMap);
const message = stringify_2.errMsg()
.matcherHint("toBeWeakMap", "received", "")
.info("Expected value to be a WeakMap, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeWeakMap);
}

@@ -306,7 +307,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeSet", "received", ""))
.write("Expected value to be a Set, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeSet);
const message = stringify_2.errMsg()
.matcherHint("toBeSet", "received", "")
.info("Expected value to be a Set, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeSet);
}

@@ -319,7 +320,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeWeakSet", "received", ""))
.write("Expected value to be a WeakSet, instead received:\n")
.write(" ", stringify_1.r(received));
throw new error_2.AssertionError(message.compose(), received, true, this.toBeWeakSet);
const message = stringify_2.errMsg()
.matcherHint("toBeWeakSet", "received", "")
.info("Expected value to be a WeakSet, instead received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeWeakSet);
}

@@ -333,9 +334,9 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeInstanceOf"))
.write("Expected value to be an instance of:\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toBeInstanceOf);
const message = stringify_2.errMsg()
.matcherHint("toBeInstanceOf")
.info("Expected value to be an instance of:\n")
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeInstanceOf);
}

@@ -349,9 +350,9 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeInstanceOf"))
.write("Expected value not to be an instance of:\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToBeInstanceOf);
const message = stringify_2.errMsg()
.matcherHint("notToBeInstanceOf")
.info("Expected value not to be an instance of:\n")
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.notToBeInstanceOf);
}

@@ -362,91 +363,2 @@ return this;

exports.Assertion = Assertion;
class ArrayAssertion extends Assertion {
toHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length === expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHaveLength"))
.write("Expected array to have a length ", stringify_1.e(expected), ", instead it have a length ", stringify_1.r(received.length), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHaveLength);
}
return this;
}
notToHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length !== expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHaveLength"))
.write("Expected array not to have a length ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHaveLength);
}
return this;
}
toContain(value) {
const received = this.obj;
const expected = value;
const pass = expected instanceof matcher_2.Matcher ?
received.some((i) => expected.match(i)) :
received.indexOf(expected) !== -1;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toContain"))
.write("Expected array to include:\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toContain);
}
return this;
}
notToContain(value) {
const received = this.obj;
const expected = value;
const pass = expected instanceof matcher_2.Matcher ?
!received.some((i) => expected.match(i)) :
received.indexOf(expected) === -1;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToContain"))
.write("Expected array not to contain:\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToContain);
}
return this;
}
toMatch(match) {
const received = this.obj;
const expected = match;
const pass = matcher_2.matchArray(received, expected);
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toMatch"))
.write("Expected array to match:\n")
.write(" ", stringify_1.e(expected), "\n")
.write("Received:\n")
.write(" ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toMatch);
}
return this;
}
notToMatch(match) {
const received = this.obj;
const expected = match;
const pass = !matcher_2.matchArray(received, expected);
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToMatch"))
.write("Expected array not to match:\n")
.write(" ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToMatch);
}
return this;
}
}
exports.ArrayAssertion = ArrayAssertion;
class NullAssertion extends Assertion {

@@ -467,18 +379,31 @@ constructor() {

exports.BooleanAssertion = BooleanAssertion;
class DateAssertion extends Assertion {
function matchException(a, b) {
if (typeof b === "string") {
if (typeof a === "string" && a.indexOf(b) !== -1) {
return true;
}
else if (a instanceof Error && a.message.indexOf(b) !== -1) {
return true;
}
}
else {
if (b instanceof Error) {
return a.constructor === b.constructor || a instanceof b.constructor;
}
else if (b.prototype instanceof Error || b === Error) {
return a.constructor === b || a instanceof b;
}
}
return false;
}
exports.DateAssertion = DateAssertion;
class ErrorAssertion extends Assertion {
}
exports.ErrorAssertion = ErrorAssertion;
class FunctionAssertion extends Assertion {
toHaveArgumentsLength(length) {
const received = this.obj;
const received = this.obj.length;
const expected = length;
const pass = received.length === expected;
const pass = received === expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHaveArgumentsLength"))
.write("Expected function to have arguments length ", stringify_1.e(expected), ", instead it have arguments length ", stringify_1.r(received.length), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHaveArgumentsLength);
const message = stringify_2.errMsg()
.matcherHint("toHaveArgumentsLength")
.info(rtext_writer_1.rt `Expected function to have arguments length ${stringify_2.e(expected)}, instead it have length ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHaveArgumentsLength);
}

@@ -492,6 +417,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHaveLength"))
.write("Expected function not to have arguments length ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHaveArgumentsLength);
const message = stringify_2.errMsg()
.matcherHint("notToHaveLength")
.info(rtext_writer_1.rt `Expected function not to have arguments length ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHaveArgumentsLength);
}

@@ -501,5 +426,3 @@ return this;

toThrow(expected) {
const received = this.obj;
let pass = false;
let throwed;
try {

@@ -509,4 +432,3 @@ this.obj();

catch (e) {
throwed = e;
if (expected !== undefined && matcher_2.matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = true;

@@ -516,6 +438,6 @@ }

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toThrow"))
.write("Expected function to throw an exception ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toThrow);
const message = stringify_2.errMsg()
.matcherHint("toThrow")
.info(rtext_writer_1.rt `Expected function to throw an exception ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.toThrow);
}

@@ -525,5 +447,3 @@ return this;

notToThrow(expected) {
const received = this.obj;
let pass = true;
let throwed;
try {

@@ -533,4 +453,3 @@ this.obj();

catch (e) {
throwed = e;
if (expected !== undefined && matcher_2.matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = false;

@@ -540,6 +459,6 @@ }

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToThrow"))
.write("Expected function not to throw an exception ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToThrow);
const message = stringify_2.errMsg()
.matcherHint("notToThrow")
.info(rtext_writer_1.rt `Expected function not to throw an exception ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToThrow);
}

@@ -550,5 +469,5 @@ return this;

exports.FunctionAssertion = FunctionAssertion;
const eB = stringify_1.e("b", true);
const rA = stringify_1.r("a", true);
const eE = stringify_1.e("epsilon", true);
const eB = stringify_2.e("b", true);
const rA = stringify_2.r("a", true);
const eE = stringify_2.e("epsilon", true);
class NumberAssertion extends Assertion {

@@ -562,9 +481,7 @@ toBeApproximatelyEqual(number, epsilon = Number.EPSILON) {

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be approximately equal to ", stringify_1.e(b), ", intstead received ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeApproximatelyEqual);
const message = stringify_2.errMsg()
.matcherHint("toBeApproximatelyEqual", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `abs(${rA} - ${eB}) <= (abs(${rA}) < abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rtext_writer_1.rt `Expected number to be approximately equal to ${stringify_2.e(b)}, intstead received ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeApproximatelyEqual);
}

@@ -580,9 +497,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be approximately equal to ", stringify_1.e(b), ", instead received ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeApproximatelyEqual);
const message = stringify_2.errMsg()
.matcherHint("notToBeApproximatelyEqual", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `!(abs(${rA} - ${eB}) <= (abs(${rA}) < abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rtext_writer_1.rt `Expected number not to be approximately equal to ${stringify_2.e(b)}, instead received ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeApproximatelyEqual);
}

@@ -598,9 +513,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be essentially equal to ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeEssentiallyEqual);
const message = stringify_2.errMsg()
.matcherHint("toBeEssentiallyEqual", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `abs(${rA} - ${eB}) <= (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rtext_writer_1.rt `Expected number to be essentially equal to ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeEssentiallyEqual);
}

@@ -616,9 +529,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be essentially equal to ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeEssentiallyEqual);
const message = stringify_2.errMsg()
.matcherHint("notToBeEssentiallyEqual", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `!(abs(${rA} - ${eB}) <= (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}) \n\n`)
.info(rtext_writer_1.rt `Expected number not to be essentially equal to ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeEssentiallyEqual);
}

@@ -634,9 +545,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", rA, " - ", eB, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely greater than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeDefinetelyGreaterThan);
const message = stringify_2.errMsg()
.matcherHint("toBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `(${rA} - ${eB}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rtext_writer_1.rt `Expected number to be definetely greater than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeDefinetelyGreaterThan);
}

@@ -652,9 +561,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", rA, " - ", eB, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely greater than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeDefinetelyGreaterThan);
const message = stringify_2.errMsg()
.matcherHint("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `!((${rA} - ${eB}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rtext_writer_1.rt `Expected number not to be definetely greater than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeDefinetelyGreaterThan);
}

@@ -670,9 +577,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", eB, " - ", rA, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely less than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeDefinetelyLessThan);
const message = stringify_2.errMsg()
.matcherHint("toBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `(${eB} - ${rA}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rtext_writer_1.rt `Expected number to be definetely less than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeDefinetelyLessThan);
}

@@ -688,9 +593,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", eB, " - ", rA, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely less than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeDefinetelyLessThan);
const message = stringify_2.errMsg()
.matcherHint("notToBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint(rtext_writer_1.rt `!((${eB} - ${rA}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rtext_writer_1.rt `Expected number not to be definetely less than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeDefinetelyLessThan);
}

@@ -704,6 +607,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeGreaterThan"))
.write("Expected number to be greater than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeGreaterThan);
const message = stringify_2.errMsg()
.matcherHint("toBeGreaterThan")
.info(rtext_writer_1.rt `Expected number to be greater than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeGreaterThan);
}

@@ -717,6 +620,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeGreaterThan"))
.write("Expected number not to be greater than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeGreaterThan);
const message = stringify_2.errMsg()
.matcherHint("notToBeGreaterThan")
.info(rtext_writer_1.rt `Expected number not to be greater than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeGreaterThan);
}

@@ -730,6 +633,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeGreaterThanOrEqual"))
.write("Expected number to be greater than or equal to ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeGreaterThanOrEqual);
const message = stringify_2.errMsg()
.matcherHint("toBeGreaterThanOrEqual")
.info(rtext_writer_1.rt `Expected number to be greater than or equal to ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeGreaterThanOrEqual);
}

@@ -743,6 +646,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeGreaterThanOrEqual"))
.write("Expected number not to be greater than or equal to ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeGreaterThanOrEqual);
const message = stringify_2.errMsg()
.matcherHint("notToBeGreaterThanOrEqual")
.info(rtext_writer_1.rt `Expected number not to be greater than or equal to ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeGreaterThanOrEqual);
}

@@ -756,6 +659,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeLessThan"))
.write("Expected number to be less than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeLessThan);
const message = stringify_2.errMsg()
.matcherHint("toBeLessThan")
.info(rtext_writer_1.rt `Expected number to be less than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeLessThan);
}

@@ -769,6 +672,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeLessThan"))
.write("Expected number not to be less than ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeLessThan);
const message = stringify_2.errMsg()
.matcherHint("notToBeLessThan")
.info(rtext_writer_1.rt `Expected number not to be less than ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeLessThan);
}

@@ -782,6 +685,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeLessThanOrEqual"))
.write("Expected number to be less than or equal to ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.toBeLessThanOrEqual);
const message = stringify_2.errMsg()
.matcherHint("toBeLessThanOrEqual")
.info(rtext_writer_1.rt `Expected number to be less than or equal to ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeLessThanOrEqual);
}

@@ -795,6 +698,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeLessThanOrEqual"))
.write("Expected number not to be less than or equal to ", stringify_1.e(b), ", instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, b, this.notToBeLessThanOrEqual);
const message = stringify_2.errMsg()
.matcherHint("notToBeLessThanOrEqual")
.info(rtext_writer_1.rt `Expected number not to be less than or equal to ${stringify_2.e(b)}, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToBeLessThanOrEqual);
}

@@ -807,6 +710,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toBeNaN", "received", ""))
.write("Expected number to be NaN, instead received: ", stringify_1.r(a), "\n");
throw new error_2.AssertionError(message.compose(), a, NaN, this.toBeNaN);
const message = stringify_2.errMsg()
.matcherHint("toBeNaN", "received", "")
.info(rtext_writer_1.rt `Expected number to be NaN, instead received: ${stringify_2.r(a)}\n`);
throw new error_2.AssertionError(message.compose(), this.toBeNaN);
}

@@ -819,6 +722,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToBeNaN", "received", ""))
.write("Expected number not to be NaN\n");
throw new error_2.AssertionError(message.compose(), a, NaN, this.notToBeNaN);
const message = stringify_2.errMsg()
.matcherHint("notToBeNaN", "received", "")
.info("Expected number not to be NaN\n");
throw new error_2.AssertionError(message.compose(), this.notToBeNaN);
}

@@ -830,11 +733,14 @@ return this;

class StringAssertion extends Assertion {
toSnapshot() {
return this.obj;
}
toHaveLength(length) {
const received = this.obj;
const received = this.obj.length;
const expected = length;
const pass = received.length === expected;
const pass = received === expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHaveLength"))
.write("Expected string to have length ", stringify_1.e(expected), ", instead it have length ", stringify_1.r(received.length), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHaveLength);
const message = stringify_2.errMsg()
.matcherHint("toHaveLength")
.info(rtext_writer_1.rt `Expected string to have length ${stringify_2.e(expected)}, instead it have length ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHaveLength);
}

@@ -844,10 +750,10 @@ return this;

notToHaveLength(length) {
const received = this.obj;
const received = this.obj.length;
const expected = length;
const pass = received.length !== expected;
const pass = received !== expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHaveLength"))
.write("Expected string not to have length ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHaveLength);
const message = stringify_2.errMsg()
.matcherHint("notToHaveLength")
.info(rtext_writer_1.rt `Expected string not to have length ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHaveLength);
}

@@ -861,7 +767,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toInclude"))
.write("Expected string to include ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toInclude);
const message = stringify_2.errMsg()
.matcherHint("toInclude")
.info(rtext_writer_1.rt `Expected string to include ${stringify_2.e(expected)}\n`)
.info(rtext_writer_1.rt `Received: ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toInclude);
}

@@ -875,7 +781,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToInclude"))
.write("Expected string not to include ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToInclude);
const message = stringify_2.errMsg()
.matcherHint("notToInclude")
.info(rtext_writer_1.rt `Expected string not to include ${stringify_2.e(expected)}\n`)
.info(rtext_writer_1.rt `Received: ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToInclude);
}

@@ -889,7 +795,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toMatch"))
.write("Expected string to match ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toMatch);
const message = stringify_2.errMsg()
.matcherHint("toMatch")
.info(rtext_writer_1.rt `Expected string to match ${stringify_2.e(expected)}\n`)
.info(rtext_writer_1.rt `Received: ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toMatch);
}

@@ -903,7 +809,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToMatch"))
.write("Expected string not to match ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToMatch);
const message = stringify_2.errMsg()
.matcherHint("notToMatch")
.info(rtext_writer_1.rt `Expected string not to match ${stringify_2.e(expected)}\n`)
.info(rtext_writer_1.rt `Received: ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToMatch);
}

@@ -918,33 +824,199 @@ return this;

class ObjectAssertion extends Assertion {
toMatch(matcher) {
constructor(obj, type = "object") {
super(obj);
this.type = type;
}
toSnapshot() {
return snapshot_1.toSnapshot(this.obj);
}
toBeEqual(expected) {
const received = this.obj;
const expected = matcher;
const pass = matcher.match(received);
const pass = lodash_1.isEqual(received, expected);
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toMatch"))
.write("Expected Object to match ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toMatch);
const message = stringify_2.errMsg()
.matcherHint("toBeEqual")
.info(`Expected ${this.type} to be equal (_.isEqual()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeEqual);
}
return this;
}
notToMatch(matcher) {
notToBeEqual(expected) {
const received = this.obj;
const expected = matcher;
const pass = !matcher.match(received);
const pass = !lodash_1.isEqual(received, expected);
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToMatch"))
.write("Expected Object not to match ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToMatch);
const message = stringify_2.errMsg()
.matcherHint("notToMatch")
.info(`Expected ${this.type} not to be equal (!_.isEqual()):\n`)
.info(" ", stringify_2.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), this.notToBeEqual);
}
return this;
}
toBeEqualWith(expected, customizer) {
const received = this.obj;
const pass = lodash_1.isEqualWith(received, expected, customizer);
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("toBeEqualWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to be equal with (_.isEqualWith()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toBeEqualWith);
}
return this;
}
notToBeEqualWith(expected, customizer) {
const received = this.obj;
const pass = !lodash_1.isEqualWith(received, expected, customizer);
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("notToBeEqualWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to be equal with (!_.isEqualWith()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.notToBeEqualWith);
}
return this;
}
toMatch(expected) {
const received = this.obj;
const pass = lodash_1.isMatch(received, expected);
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("toMatch")
.info(`Expected ${this.type} to match (_.isMatch()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toMatch);
}
return this;
}
notToMatch(expected) {
const received = this.obj;
const pass = !lodash_1.isMatch(received, expected);
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("notToMatch")
.info(`Expected ${this.type} not to match (!_.isMatch()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.notToMatch);
}
return this;
}
toMatchWith(expected, customizer) {
const received = this.obj;
const pass = lodash_1.isMatchWith(received, expected, customizer);
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("toMatchWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to match with customizer (_.isMatchWith()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toMatchWith);
}
return this;
}
notToMatchWith(expected, customizer) {
const received = this.obj;
const pass = !lodash_1.isMatchWith(received, expected, customizer);
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("notToMatchWith", "received", "expected", "customizer")
.info(`Expected ${this.type} not to match with customizer (!_.isMatchWith()):\n`)
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.notToMatchWith);
}
return this;
}
}
exports.ObjectAssertion = ObjectAssertion;
class RegExpAssertion extends Assertion {
class ArrayAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "array");
}
toHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length === expected;
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("toHaveLength")
.info(rtext_writer_1.rt `Expected array to have a length ${stringify_2.e(expected)} instead it have a length ${stringify_2.r(received.length)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHaveLength);
}
return this;
}
notToHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length !== expected;
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("notToHaveLength")
.info(rtext_writer_1.rt `Expected array not to have a length ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHaveLength);
}
return this;
}
toContain(value) {
const received = this.obj;
const expected = value;
const pass = received.indexOf(expected) !== -1;
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("toContain")
.info("Expected array to contain:\n")
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.toContain);
}
return this;
}
notToContain(value) {
const received = this.obj;
const expected = value;
const pass = received.indexOf(expected) === -1;
if (!pass) {
const message = stringify_2.errMsg()
.matcherHint("notToContain")
.info("Expected array not to contain:\n")
.info(" ", stringify_2.e(expected), "\n")
.info("Received:\n")
.info(" ", stringify_2.r(received), "\n");
throw new error_2.AssertionError(message.compose(), this.notToContain);
}
return this;
}
}
exports.ArrayAssertion = ArrayAssertion;
class DateAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Date");
}
}
exports.DateAssertion = DateAssertion;
class ErrorAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Error");
}
}
exports.ErrorAssertion = ErrorAssertion;
class RegExpAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "RegExp");
}
toSnapshot() {
return this.obj.valueOf();
return this.obj.valueOf().toString();
}

@@ -956,7 +1028,7 @@ toTest(text) {

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toTest"))
.write("Expected RegExp to test ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toTest);
const message = stringify_2.errMsg()
.matcherHint("toTest")
.info(rtext_writer_1.rt `Expected RegExp to test ${stringify_2.e(expected)}\n`)
.info(rtext_writer_1.rt `Received: ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toTest);
}

@@ -970,7 +1042,7 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToTest"))
.write("Expected RegExp not to test ", stringify_1.e(expected), "\n")
.write("Received: ", stringify_1.r(received), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToTest);
const message = stringify_2.errMsg()
.matcherHint("notToTest")
.info(rtext_writer_1.rt `Expected RegExp not to test ${stringify_2.e(expected)}\n`)
.info(rtext_writer_1.rt `Received: ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToTest);
}

@@ -981,12 +1053,15 @@ return this;

exports.RegExpAssertion = RegExpAssertion;
class MapAssertion extends Assertion {
class MapAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Map");
}
toHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size === expected;
const pass = received === expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHaveSize"))
.write("Expected Map to have size ", stringify_1.e(expected), ", instead it have size ", stringify_1.r(received.size), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHaveSize);
const message = stringify_2.errMsg()
.matcherHint("toHaveSize")
.info(rtext_writer_1.rt `Expected Map to have size ${stringify_2.e(expected)}, instead it have size ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHaveSize);
}

@@ -996,10 +1071,10 @@ return this;

notToHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size !== expected;
const pass = received !== expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHaveSize"))
.write("Expected Map not to have size ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHaveSize);
const message = stringify_2.errMsg()
.matcherHint("notToHaveSize")
.info(rtext_writer_1.rt `Expected Map not to have size ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHaveSize);
}

@@ -1013,6 +1088,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHave"))
.write("Expected Map to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHave);
const message = stringify_2.errMsg()
.matcherHint("toHave")
.info(rtext_writer_1.rt `Expected Map to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHave);
}

@@ -1026,6 +1101,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHave"))
.write("Expected Map not to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHave);
const message = stringify_2.errMsg()
.matcherHint("notToHave")
.info(rtext_writer_1.rt `Expected Map not to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHave);
}

@@ -1036,12 +1111,15 @@ return this;

exports.MapAssertion = MapAssertion;
class SetAssertion extends Assertion {
class SetAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Set");
}
toHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size === expected;
const pass = received === expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHaveSize"))
.write("Expected Set to have size ", stringify_1.e(expected), ", instead it have size ", stringify_1.r(received.size), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHaveSize);
const message = stringify_2.errMsg()
.matcherHint("toHaveSize")
.info(rtext_writer_1.rt `Expected Set to have size ${stringify_2.e(expected)}, instead it have size ${stringify_2.r(received)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHaveSize);
}

@@ -1051,10 +1129,10 @@ return this;

notToHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size !== expected;
const pass = received !== expected;
if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHaveSize"))
.write("Expected Set not to have size ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHaveSize);
const message = stringify_2.errMsg()
.matcherHint("notToHaveSize")
.info(rtext_writer_1.rt `Expected Set not to have size ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHaveSize);
}

@@ -1068,6 +1146,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHave"))
.write("Expected Set to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHave);
const message = stringify_2.errMsg()
.matcherHint("toHave")
.info(rtext_writer_1.rt `Expected Set to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHave);
}

@@ -1081,6 +1159,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHave"))
.write("Expected Set not to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHave);
const message = stringify_2.errMsg()
.matcherHint("notToHave")
.info(rtext_writer_1.rt `Expected Set not to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHave);
}

@@ -1091,3 +1169,6 @@ return this;

exports.SetAssertion = SetAssertion;
class WeakMapAssertion extends Assertion {
class WeakMapAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "WeakMap");
}
toHave(key) {

@@ -1098,6 +1179,6 @@ const received = this.obj;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHave"))
.write("Expected WeakMap to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHave);
const message = stringify_2.errMsg()
.matcherHint("toHave")
.info(rtext_writer_1.rt `Expected WeakMap to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHave);
}

@@ -1111,6 +1192,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHave"))
.write("Expected WeakMap not to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHave);
const message = stringify_2.errMsg()
.matcherHint("notToHave")
.info(rtext_writer_1.rt `Expected WeakMap not to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHave);
}

@@ -1121,3 +1202,6 @@ return this;

exports.WeakMapAssertion = WeakMapAssertion;
class WeakSetAssertion extends Assertion {
class WeakSetAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "WeakSet");
}
toHave(value) {

@@ -1128,6 +1212,6 @@ const received = this.obj;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("toHave"))
.write("Expected WeakSet to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.toHave);
const message = stringify_2.errMsg()
.matcherHint("toHave")
.info(rtext_writer_1.rt `Expected WeakSet to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.toHave);
}

@@ -1141,6 +1225,6 @@ return this;

if (!pass) {
const message = rtext_writer_1.richText()
.write(stringify_1.mh("notToHave"))
.write("Expected WeakSet not to have ", stringify_1.e(expected), "\n");
throw new error_2.AssertionError(message.compose(), received, true, this.notToHave);
const message = stringify_2.errMsg()
.matcherHint("notToHave")
.info(rtext_writer_1.rt `Expected WeakSet not to have ${stringify_2.e(expected)}\n`);
throw new error_2.AssertionError(message.compose(), this.notToHave);
}

@@ -1147,0 +1231,0 @@ return this;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const prettyFormat = require("pretty-format");
const rtext_writer_1 = require("rtext-writer");
const PLUGINS = [

@@ -31,96 +32,24 @@ prettyFormat.plugins.HTMLElement,

exports.stringify = stringify;
const NUMBERS = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
];
function pluralize(word, count) {
const result = ((count < NUMBERS.length) ? NUMBERS[count] : count.toString()) + " " + word;
if (count === 1) {
return result;
}
return result + "s";
function leftPad(p, s) {
return s.replace(/^/gm, p);
}
exports.pluralize = pluralize;
function matcherHint(writer, matcherName, received = "received", expected = "expected", secondArgument) {
writer
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(`).${matcherName}(`)
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
writer
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
writer
.write(")")
.write("\n\n")
.end("matcherHint");
exports.leftPad = leftPad;
/**
* hl is a function that highlights matched text regions. By default it highlights trailing whitespaces.
*
* @param text Raw text.
* @param regexp RegExp matcher.
* @param type Annotation type.
* @returns Rich Text.
*/
function hl(text, regexp = /\s+$/gm, type = "highlight") {
return rtext_writer_1.annotate(text, regexp, type);
}
exports.matcherHint = matcherHint;
function highlightTrailingWhitespace(text) {
const re = /\s+$/gm;
let match = re.exec(text);
const annotations = [];
while (match !== null) {
const start = match.index;
const end = start + match[0].length;
annotations.push({
type: "trailingWhitespace",
start: start,
end: end,
data: undefined,
key: undefined,
});
match = re.exec(text);
}
return {
text: text,
annotations: annotations.length === 0 ? undefined : annotations,
};
}
exports.highlightTrailingWhitespace = highlightTrailingWhitespace;
function printReceived(writer, value, raw) {
writer
.begin("received")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("received");
}
exports.printReceived = printReceived;
function printExpected(writer, value, raw) {
writer
.begin("expected")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("expected");
}
exports.printExpected = printExpected;
function printInfo(writer, s) {
writer
.begin("info")
.write(s)
.end("info");
}
exports.printInfo = printInfo;
function mh(matcherName, received = "received", expected = "expected", secondArgument) {
return function (w) {
matcherHint(w, matcherName, received, expected, secondArgument);
};
}
exports.mh = mh;
exports.hl = hl;
function r(value, raw) {
return function (w) {
printReceived(w, value, raw);
return function (writer) {
writer
.begin("received")
.write(raw ? value : hl(stringify(value)))
.end("received");
};

@@ -130,13 +59,70 @@ }

function e(value, raw) {
return function (w) {
printExpected(w, value, raw);
return function (writer) {
writer
.begin("expected")
.write(raw ? value : hl(stringify(value)))
.end("expected");
};
}
exports.e = e;
function info(s) {
return function (w) {
printInfo(w, s);
};
class ErrorMessageWriter extends rtext_writer_1.RichTextWriter {
matcherHint(matcherName, received = "received", expected = "expected", secondArgument) {
this
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(`).${matcherName}(`)
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
this
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
this
.write(")")
.write("\n\n")
.end("matcherHint");
return this;
}
hint(...ws) {
this
.continue("hint")
.write(...ws)
.end("hint");
return this;
}
info(...ws) {
this
.continue("info")
.write(...ws)
.end("info");
return this;
}
diff(...ws) {
this
.begin("diff")
.write(...ws)
.end("diff");
return this;
}
received(value) {
this
.begin("received")
.write(hl(stringify(value)))
.end("received");
return this;
}
expected(value) {
this
.begin("expected")
.write(hl(stringify(value)))
.end("expected");
return this;
}
}
exports.info = info;
exports.ErrorMessageWriter = ErrorMessageWriter;
function errMsg() {
return new ErrorMessageWriter();
}
exports.errMsg = errMsg;
//# sourceMappingURL=stringify.js.map
import * as prettyFormat from "pretty-format";
import { richText } from "rtext-writer";
import { diffLines, structuredPatch } from "diff";
import { highlightTrailingWhitespace } from "./stringify";
var NO_DIFF_MESSAGE = richText()
.begin("hint")
.write("Compared values have no visual difference.")
.end("hint")
import { errMsg, hl } from "./stringify";
var NO_DIFF_MESSAGE = errMsg()
.hint("Compared values have no visual difference.")
.compose();
var SIMILAR_MESSAGE = richText()
.begin("hint")
.write("Compared values serialize to the same structure.\n")
.write("Printing internal object structure without calling `toJSON` instead.")
.end("hint")
var SIMILAR_MESSAGE = errMsg()
.hint("Compared values serialize to the same structure.\n")
.hint("Printing internal object structure without calling `toJSON` instead.")
.compose();

@@ -43,3 +39,3 @@ var DIFF_CONTEXT = 5;

while (j < lines.length) {
result.begin("+").write("+ ", highlightTrailingWhitespace(lines[j++]), "\n").end("+");
result.begin("+").write("+ ", hl(lines[j++]), "\n").end("+");
}

@@ -50,3 +46,3 @@ }

while (j < lines.length) {
result.begin("-").write("- ", highlightTrailingWhitespace(lines[j++]), "\n").end("-");
result.begin("-").write("- ", hl(lines[j++]), "\n").end("-");
}

@@ -56,3 +52,3 @@ }

while (j < lines.length) {
result.write(" ", highlightTrailingWhitespace(lines[j++]), "\n");
result.write(" ", hl(lines[j++]), "\n");
}

@@ -106,3 +102,3 @@ }

var line = lines[j];
var highlightedLined = highlightTrailingWhitespace(line);
var highlightedLined = hl(line);
var added = line.charCodeAt(0) === 43; // +

@@ -109,0 +105,0 @@ var removed = line.charCodeAt(0) === 45; // -

@@ -5,8 +5,5 @@ import * as tslib_1 from "tslib";

tslib_1.__extends(AssertionError, _super);
function AssertionError(message, actual, expected, ssf) {
function AssertionError(message, ssf) {
var _this = _super.call(this, message.text) || this;
_this.actual = actual;
if (expected !== undefined) {
_this.expected = expected;
}
_this.$$type = "AssertionError";
if (message.annotations !== null) {

@@ -13,0 +10,0 @@ _this.annotations = message.annotations;

import * as tslib_1 from "tslib";
export { AssertionError } from "./error";
export { Matcher, m } from "./matcher";
export { ErrorMessageWriter, errMsg, r, e, hl, stringify } from "./stringify";
export { diff } from "./diff";
import { rt } from "rtext-writer";
import { AssertionError } from "./error";
import { diff } from "./diff";
import { richText } from "rtext-writer";
import { AssertionError } from "./error";
import { mh, r, e } from "./stringify";
import { Matcher, matchArray, matchException } from "./matcher";
import { errMsg, r, e } from "./stringify";
import { toSnapshot } from "./snapshot";
import { isEqual, isEqualWith, isMatch, isMatchWith } from "lodash";
var Assertion = (function () {

@@ -14,3 +16,3 @@ function Assertion(obj) {

Assertion.prototype.toSnapshot = function () {
return this.obj;
return this.obj.toString();
};

@@ -20,3 +22,3 @@ Assertion.prototype.assert = function (expr, message, expected, actual) {

if (pass === false) {
throw new AssertionError(message(expected, actual), actual, expected, this.assert);
throw new AssertionError(message(expected, actual), this.assert);
}

@@ -29,7 +31,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeFalsy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, false, this.toBeFalsy);
var message = errMsg()
.matcherHint("toBeFalsy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeFalsy);
}

@@ -42,7 +44,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeTruthy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeTruthy);
var message = errMsg()
.matcherHint("toBeTruthy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeTruthy);
}

@@ -57,16 +59,12 @@ return this;

var diffText = diff(expected, received);
var message = richText()
.write(mh("toBe"))
.write("Expected value to be (strict equality ===):\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
var message = errMsg()
.matcherHint("toBe")
.info("Expected value to be (strict equality ===):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
if (diffText !== null) {
message
.begin("diff")
.write("\n", "Difference:\n\n")
.write(diffText)
.end("diff");
message.diff("\nDifference:\n\n", diffText);
}
throw new AssertionError(message.compose(), received, expected, this.toBe);
throw new AssertionError(message.compose(), this.toBe);
}

@@ -80,9 +78,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("notToBe"))
.write("Expected value not to be (strict inequality !==):\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, expected, this.toBe);
var message = errMsg()
.matcherHint("notToBe")
.info("Expected value not to be (strict inequality !==):\n")
.info(" ", e(expected), "\n");
throw new AssertionError(message.compose(), this.toBe);
}

@@ -95,7 +91,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeNull", "received", ""))
.write("Expected value to be null, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeNull);
var message = errMsg()
.matcherHint("toBeNull", "received", "")
.info("Expected value to be null, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeNull);
}

@@ -108,6 +104,6 @@ return this;

if (!pass) {
var message = richText()
.write(mh("notToBeNull", "received", ""))
.write("Expected value not to be null\n");
throw new AssertionError(message.compose(), received, true, this.notToBeNull);
var message = errMsg()
.matcherHint("notToBeNull", "received", "")
.info("Expected value not to be null\n");
throw new AssertionError(message.compose(), this.notToBeNull);
}

@@ -120,7 +116,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeUndefined", "received", ""))
.write("Expected value to be undefined, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeUndefined);
var message = errMsg()
.matcherHint("toBeUndefined", "received", "")
.info("Expected value to be undefined, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeUndefined);
}

@@ -133,6 +129,6 @@ return this;

if (!pass) {
var message = richText()
.write(mh("notToBeUndefined", "received", ""))
.write("Expected value not to be undefined\n");
throw new AssertionError(message.compose(), received, true, this.notToBeUndefined);
var message = errMsg()
.matcherHint("notToBeUndefined", "received", "")
.info("Expected value not to be undefined\n");
throw new AssertionError(message.compose(), this.notToBeUndefined);
}

@@ -145,7 +141,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeObject", "received", ""))
.write("Expected value to be an object, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeObject);
var message = errMsg()
.matcherHint("toBeObject", "received", "")
.info("Expected value to be an object, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeObject);
}

@@ -158,7 +154,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeArray", "received", ""))
.write("Expected value to be an array, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeArray);
var message = errMsg()
.matcherHint("toBeArray", "received", "")
.info("Expected value to be an array, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeArray);
}

@@ -171,7 +167,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeBoolean", "received", ""))
.write("Expected value to be a boolean, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeBoolean);
var message = errMsg()
.matcherHint("toBeBoolean", "received", "")
.info("Expected value to be a boolean, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeBoolean);
}

@@ -184,7 +180,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeNumber", "received", ""))
.write("Expected value to be a number, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeNumber);
var message = errMsg()
.matcherHint("toBeNumber", "received", "")
.info("Expected value to be a number, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeNumber);
}

@@ -197,7 +193,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeString", "received", ""))
.write("Expected value to be a string, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeString);
var message = errMsg()
.matcherHint("toBeString", "received", "")
.info("Expected value to be a string, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeString);
}

@@ -210,7 +206,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeFunction", "received", ""))
.write("Expected value to be a function, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeFunction);
var message = errMsg()
.matcherHint("toBeFunction", "received", "")
.info("Expected value to be a function, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeFunction);
}

@@ -223,7 +219,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeSymbol", "received", ""))
.write("Expected value to be a symbol, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeSymbol);
var message = errMsg()
.matcherHint("toBeSymbol", "received", "")
.info("Expected value to be a symbol, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeSymbol);
}

@@ -236,7 +232,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeDate", "received", ""))
.write("Expected value to be a Date, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeDate);
var message = errMsg()
.matcherHint("toBeDate", "received", "")
.info("Expected value to be a Date, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeDate);
}

@@ -249,7 +245,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeRegExp", "received", ""))
.write("Expected value to be a RegExp, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeRegExp);
var message = errMsg()
.matcherHint("toBeRegExp", "received", "")
.info("Expected value to be a RegExp, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeRegExp);
}

@@ -262,7 +258,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeError", "received", ""))
.write("Expected value to be an Error, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeError);
var message = errMsg()
.matcherHint("toBeError", "received", "")
.info("Expected value to be an Error, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeError);
}

@@ -275,7 +271,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeMap", "received", ""))
.write("Expected value to be a Map, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeMap);
var message = errMsg()
.matcherHint("toBeMap", "received", "")
.info("Expected value to be a Map, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeMap);
}

@@ -288,7 +284,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeWeakMap", "received", ""))
.write("Expected value to be a WeakMap, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeWeakMap);
var message = errMsg()
.matcherHint("toBeWeakMap", "received", "")
.info("Expected value to be a WeakMap, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeWeakMap);
}

@@ -301,7 +297,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeSet", "received", ""))
.write("Expected value to be a Set, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeSet);
var message = errMsg()
.matcherHint("toBeSet", "received", "")
.info("Expected value to be a Set, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeSet);
}

@@ -314,7 +310,7 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeWeakSet", "received", ""))
.write("Expected value to be a WeakSet, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeWeakSet);
var message = errMsg()
.matcherHint("toBeWeakSet", "received", "")
.info("Expected value to be a WeakSet, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeWeakSet);
}

@@ -328,9 +324,9 @@ return this;

if (!pass) {
var message = richText()
.write(mh("toBeInstanceOf"))
.write("Expected value to be an instance of:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeInstanceOf);
var message = errMsg()
.matcherHint("toBeInstanceOf")
.info("Expected value to be an instance of:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeInstanceOf);
}

@@ -344,9 +340,9 @@ return this;

if (!pass) {
var message = richText()
.write(mh("notToBeInstanceOf"))
.write("Expected value not to be an instance of:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToBeInstanceOf);
var message = errMsg()
.matcherHint("notToBeInstanceOf")
.info("Expected value not to be an instance of:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToBeInstanceOf);
}

@@ -358,96 +354,2 @@ return this;

export { Assertion };
var ArrayAssertion = (function (_super) {
tslib_1.__extends(ArrayAssertion, _super);
function ArrayAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
}
ArrayAssertion.prototype.toHaveLength = function (length) {
var received = this.obj;
var expected = length;
var pass = received.length === expected;
if (!pass) {
var message = richText()
.write(mh("toHaveLength"))
.write("Expected array to have a length ", e(expected), ", instead it have a length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveLength);
}
return this;
};
ArrayAssertion.prototype.notToHaveLength = function (length) {
var received = this.obj;
var expected = length;
var pass = received.length !== expected;
if (!pass) {
var message = richText()
.write(mh("notToHaveLength"))
.write("Expected array not to have a length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveLength);
}
return this;
};
ArrayAssertion.prototype.toContain = function (value) {
var received = this.obj;
var expected = value;
var pass = expected instanceof Matcher ?
received.some(function (i) { return expected.match(i); }) :
received.indexOf(expected) !== -1;
if (!pass) {
var message = richText()
.write(mh("toContain"))
.write("Expected array to include:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toContain);
}
return this;
};
ArrayAssertion.prototype.notToContain = function (value) {
var received = this.obj;
var expected = value;
var pass = expected instanceof Matcher ?
!received.some(function (i) { return expected.match(i); }) :
received.indexOf(expected) === -1;
if (!pass) {
var message = richText()
.write(mh("notToContain"))
.write("Expected array not to contain:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToContain);
}
return this;
};
ArrayAssertion.prototype.toMatch = function (match) {
var received = this.obj;
var expected = match;
var pass = matchArray(received, expected);
if (!pass) {
var message = richText()
.write(mh("toMatch"))
.write("Expected array to match:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
}
return this;
};
ArrayAssertion.prototype.notToMatch = function (match) {
var received = this.obj;
var expected = match;
var pass = !matchArray(received, expected);
if (!pass) {
var message = richText()
.write(mh("notToMatch"))
.write("Expected array not to match:\n")
.write(" ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
}
return this;
};
return ArrayAssertion;
}(Assertion));
export { ArrayAssertion };
var NullAssertion = (function (_super) {

@@ -477,18 +379,21 @@ tslib_1.__extends(NullAssertion, _super);

export { BooleanAssertion };
var DateAssertion = (function (_super) {
tslib_1.__extends(DateAssertion, _super);
function DateAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function matchException(a, b) {
if (typeof b === "string") {
if (typeof a === "string" && a.indexOf(b) !== -1) {
return true;
}
else if (a instanceof Error && a.message.indexOf(b) !== -1) {
return true;
}
}
return DateAssertion;
}(Assertion));
export { DateAssertion };
var ErrorAssertion = (function (_super) {
tslib_1.__extends(ErrorAssertion, _super);
function ErrorAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
else {
if (b instanceof Error) {
return a.constructor === b.constructor || a instanceof b.constructor;
}
else if (b.prototype instanceof Error || b === Error) {
return a.constructor === b || a instanceof b;
}
}
return ErrorAssertion;
}(Assertion));
export { ErrorAssertion };
return false;
}
var FunctionAssertion = (function (_super) {

@@ -500,12 +405,13 @@ tslib_1.__extends(FunctionAssertion, _super);

FunctionAssertion.prototype.toHaveArgumentsLength = function (length) {
var received = this.obj;
var received = this.obj.length;
var expected = length;
var pass = received.length === expected;
var pass = received === expected;
if (!pass) {
var message = richText()
.write(mh("toHaveArgumentsLength"))
.write("Expected function to have arguments length ", e(expected), ", instead it have arguments length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveArgumentsLength);
var message = errMsg()
.matcherHint("toHaveArgumentsLength")
.info((_a = ["Expected function to have arguments length ", ", instead it have length ", "\n"], _a.raw = ["Expected function to have arguments length ", ", instead it have length ", "\\n"], rt(_a, e(expected), r(received))));
throw new AssertionError(message.compose(), this.toHaveArgumentsLength);
}
return this;
var _a;
};

@@ -517,13 +423,12 @@ FunctionAssertion.prototype.notToHaveArgumentsLength = function (length) {

if (!pass) {
var message = richText()
.write(mh("notToHaveLength"))
.write("Expected function not to have arguments length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveArgumentsLength);
var message = errMsg()
.matcherHint("notToHaveLength")
.info((_a = ["Expected function not to have arguments length ", "\n"], _a.raw = ["Expected function not to have arguments length ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHaveArgumentsLength);
}
return this;
var _a;
};
FunctionAssertion.prototype.toThrow = function (expected) {
var received = this.obj;
var pass = false;
var throwed;
try {

@@ -533,4 +438,3 @@ this.obj();

catch (e) {
throwed = e;
if (expected !== undefined && matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = true;

@@ -540,13 +444,12 @@ }

if (!pass) {
var message = richText()
.write(mh("toThrow"))
.write("Expected function to throw an exception ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toThrow);
var message = errMsg()
.matcherHint("toThrow")
.info((_a = ["Expected function to throw an exception ", "\n"], _a.raw = ["Expected function to throw an exception ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.toThrow);
}
return this;
var _a;
};
FunctionAssertion.prototype.notToThrow = function (expected) {
var received = this.obj;
var pass = true;
var throwed;
try {

@@ -556,4 +459,3 @@ this.obj();

catch (e) {
throwed = e;
if (expected !== undefined && matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = false;

@@ -563,8 +465,9 @@ }

if (!pass) {
var message = richText()
.write(mh("notToThrow"))
.write("Expected function not to throw an exception ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToThrow);
var message = errMsg()
.matcherHint("notToThrow")
.info((_a = ["Expected function not to throw an exception ", "\n"], _a.raw = ["Expected function not to throw an exception ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToThrow);
}
return this;
var _a;
};

@@ -590,11 +493,10 @@ return FunctionAssertion;

if (!pass) {
var message = richText()
.write(mh("toBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be approximately equal to ", e(b), ", intstead received ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeApproximatelyEqual);
var message = errMsg()
.matcherHint("toBeApproximatelyEqual", "received", "expected", "epsilon")
.hint((_a = ["abs(", " - ", ") <= (abs(", ") < abs(", ") ? abs(", ") : abs(", ")) * ", "\n\n"], _a.raw = ["abs(", " - ", ") <= (abs(", ") < abs(", ") ? abs(", ") : abs(", ")) * ", "\\n\\n"], rt(_a, rA, eB, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number to be approximately equal to ", ", intstead received ", "\n"], _b.raw = ["Expected number to be approximately equal to ", ", intstead received ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeApproximatelyEqual);
}
return this;
var _a, _b;
};

@@ -609,11 +511,10 @@ NumberAssertion.prototype.notToBeApproximatelyEqual = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("notToBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be approximately equal to ", e(b), ", instead received ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeApproximatelyEqual);
var message = errMsg()
.matcherHint("notToBeApproximatelyEqual", "received", "expected", "epsilon")
.hint((_a = ["!(abs(", " - ", ") <= (abs(", ") < abs(", ") ? abs(", ") : abs(", ")) * ", ")\n\n"], _a.raw = ["!(abs(", " - ", ") <= (abs(", ") < abs(", ") ? abs(", ") : abs(", ")) * ", ")\\n\\n"], rt(_a, rA, eB, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number not to be approximately equal to ", ", instead received ", "\n"], _b.raw = ["Expected number not to be approximately equal to ", ", instead received ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeApproximatelyEqual);
}
return this;
var _a, _b;
};

@@ -628,11 +529,10 @@ NumberAssertion.prototype.toBeEssentiallyEqual = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("toBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be essentially equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeEssentiallyEqual);
var message = errMsg()
.matcherHint("toBeEssentiallyEqual", "received", "expected", "epsilon")
.hint((_a = ["abs(", " - ", ") <= (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", "\n\n"], _a.raw = ["abs(", " - ", ") <= (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", "\\n\\n"], rt(_a, rA, eB, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number to be essentially equal to ", ", instead received: ", "\n"], _b.raw = ["Expected number to be essentially equal to ", ", instead received: ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeEssentiallyEqual);
}
return this;
var _a, _b;
};

@@ -647,11 +547,10 @@ NumberAssertion.prototype.notToBeEssentiallyEqual = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("notToBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be essentially equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeEssentiallyEqual);
var message = errMsg()
.matcherHint("notToBeEssentiallyEqual", "received", "expected", "epsilon")
.hint((_a = ["!(abs(", " - ", ") <= (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", ") \n\n"], _a.raw = ["!(abs(", " - ", ") <= (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", ") \\n\\n"], rt(_a, rA, eB, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number not to be essentially equal to ", ", instead received: ", "\n"], _b.raw = ["Expected number not to be essentially equal to ", ", instead received: ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeEssentiallyEqual);
}
return this;
var _a, _b;
};

@@ -666,11 +565,10 @@ NumberAssertion.prototype.toBeDefinetelyGreaterThan = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("toBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", rA, " - ", eB, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeDefinetelyGreaterThan);
var message = errMsg()
.matcherHint("toBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint((_a = ["(", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", "\n\n"], _a.raw = ["(", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", "\\n\\n"], rt(_a, rA, eB, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number to be definetely greater than ", ", instead received: ", "\n"], _b.raw = ["Expected number to be definetely greater than ", ", instead received: ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeDefinetelyGreaterThan);
}
return this;
var _a, _b;
};

@@ -685,11 +583,10 @@ NumberAssertion.prototype.notToBeDefinetelyGreaterThan = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", rA, " - ", eB, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeDefinetelyGreaterThan);
var message = errMsg()
.matcherHint("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint((_a = ["!((", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", ")\n\n"], _a.raw = ["!((", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", ")\\n\\n"], rt(_a, rA, eB, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number not to be definetely greater than ", ", instead received: ", "\n"], _b.raw = ["Expected number not to be definetely greater than ", ", instead received: ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeDefinetelyGreaterThan);
}
return this;
var _a, _b;
};

@@ -704,11 +601,10 @@ NumberAssertion.prototype.toBeDefinetelyLessThan = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("toBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", eB, " - ", rA, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeDefinetelyLessThan);
var message = errMsg()
.matcherHint("toBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint((_a = ["(", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", "\n\n"], _a.raw = ["(", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", "\\n\\n"], rt(_a, eB, rA, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number to be definetely less than ", ", instead received: ", "\n"], _b.raw = ["Expected number to be definetely less than ", ", instead received: ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeDefinetelyLessThan);
}
return this;
var _a, _b;
};

@@ -723,11 +619,10 @@ NumberAssertion.prototype.notToBeDefinetelyLessThan = function (number, epsilon) {

if (!pass) {
var message = richText()
.write(mh("notToBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", eB, " - ", rA, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeDefinetelyLessThan);
var message = errMsg()
.matcherHint("notToBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint((_a = ["!((", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", ")\n\n"], _a.raw = ["!((", " - ", ") > (abs(", ") > abs(", ") ? abs(", ") : abs(", ")) * ", ")\\n\\n"], rt(_a, eB, rA, rA, eB, eB, rA, eE)))
.info((_b = ["Expected number not to be definetely less than ", ", instead received: ", "\n"], _b.raw = ["Expected number not to be definetely less than ", ", instead received: ", "\\n"], rt(_b, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeDefinetelyLessThan);
}
return this;
var _a, _b;
};

@@ -739,8 +634,9 @@ NumberAssertion.prototype.toBeGreaterThan = function (number) {

if (!pass) {
var message = richText()
.write(mh("toBeGreaterThan"))
.write("Expected number to be greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeGreaterThan);
var message = errMsg()
.matcherHint("toBeGreaterThan")
.info((_a = ["Expected number to be greater than ", ", instead received: ", "\n"], _a.raw = ["Expected number to be greater than ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeGreaterThan);
}
return this;
var _a;
};

@@ -752,8 +648,9 @@ NumberAssertion.prototype.notToBeGreaterThan = function (number) {

if (!pass) {
var message = richText()
.write(mh("notToBeGreaterThan"))
.write("Expected number not to be greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeGreaterThan);
var message = errMsg()
.matcherHint("notToBeGreaterThan")
.info((_a = ["Expected number not to be greater than ", ", instead received: ", "\n"], _a.raw = ["Expected number not to be greater than ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeGreaterThan);
}
return this;
var _a;
};

@@ -765,8 +662,9 @@ NumberAssertion.prototype.toBeGreaterThanOrEqual = function (number) {

if (!pass) {
var message = richText()
.write(mh("toBeGreaterThanOrEqual"))
.write("Expected number to be greater than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeGreaterThanOrEqual);
var message = errMsg()
.matcherHint("toBeGreaterThanOrEqual")
.info((_a = ["Expected number to be greater than or equal to ", ", instead received: ", "\n"], _a.raw = ["Expected number to be greater than or equal to ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeGreaterThanOrEqual);
}
return this;
var _a;
};

@@ -778,8 +676,9 @@ NumberAssertion.prototype.notToBeGreaterThanOrEqual = function (number) {

if (!pass) {
var message = richText()
.write(mh("notToBeGreaterThanOrEqual"))
.write("Expected number not to be greater than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeGreaterThanOrEqual);
var message = errMsg()
.matcherHint("notToBeGreaterThanOrEqual")
.info((_a = ["Expected number not to be greater than or equal to ", ", instead received: ", "\n"], _a.raw = ["Expected number not to be greater than or equal to ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeGreaterThanOrEqual);
}
return this;
var _a;
};

@@ -791,8 +690,9 @@ NumberAssertion.prototype.toBeLessThan = function (number) {

if (!pass) {
var message = richText()
.write(mh("toBeLessThan"))
.write("Expected number to be less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeLessThan);
var message = errMsg()
.matcherHint("toBeLessThan")
.info((_a = ["Expected number to be less than ", ", instead received: ", "\n"], _a.raw = ["Expected number to be less than ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeLessThan);
}
return this;
var _a;
};

@@ -804,8 +704,9 @@ NumberAssertion.prototype.notToBeLessThan = function (number) {

if (!pass) {
var message = richText()
.write(mh("notToBeLessThan"))
.write("Expected number not to be less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeLessThan);
var message = errMsg()
.matcherHint("notToBeLessThan")
.info((_a = ["Expected number not to be less than ", ", instead received: ", "\n"], _a.raw = ["Expected number not to be less than ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeLessThan);
}
return this;
var _a;
};

@@ -817,8 +718,9 @@ NumberAssertion.prototype.toBeLessThanOrEqual = function (number) {

if (!pass) {
var message = richText()
.write(mh("toBeLessThanOrEqual"))
.write("Expected number to be less than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeLessThanOrEqual);
var message = errMsg()
.matcherHint("toBeLessThanOrEqual")
.info((_a = ["Expected number to be less than or equal to ", ", instead received: ", "\n"], _a.raw = ["Expected number to be less than or equal to ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.toBeLessThanOrEqual);
}
return this;
var _a;
};

@@ -830,8 +732,9 @@ NumberAssertion.prototype.notToBeLessThanOrEqual = function (number) {

if (!pass) {
var message = richText()
.write(mh("notToBeLessThanOrEqual"))
.write("Expected number not to be less than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeLessThanOrEqual);
var message = errMsg()
.matcherHint("notToBeLessThanOrEqual")
.info((_a = ["Expected number not to be less than or equal to ", ", instead received: ", "\n"], _a.raw = ["Expected number not to be less than or equal to ", ", instead received: ", "\\n"], rt(_a, e(b), r(a))));
throw new AssertionError(message.compose(), this.notToBeLessThanOrEqual);
}
return this;
var _a;
};

@@ -842,8 +745,9 @@ NumberAssertion.prototype.toBeNaN = function () {

if (!pass) {
var message = richText()
.write(mh("toBeNaN", "received", ""))
.write("Expected number to be NaN, instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, NaN, this.toBeNaN);
var message = errMsg()
.matcherHint("toBeNaN", "received", "")
.info((_a = ["Expected number to be NaN, instead received: ", "\n"], _a.raw = ["Expected number to be NaN, instead received: ", "\\n"], rt(_a, r(a))));
throw new AssertionError(message.compose(), this.toBeNaN);
}
return this;
var _a;
};

@@ -854,6 +758,6 @@ NumberAssertion.prototype.notToBeNaN = function () {

if (!pass) {
var message = richText()
.write(mh("notToBeNaN", "received", ""))
.write("Expected number not to be NaN\n");
throw new AssertionError(message.compose(), a, NaN, this.notToBeNaN);
var message = errMsg()
.matcherHint("notToBeNaN", "received", "")
.info("Expected number not to be NaN\n");
throw new AssertionError(message.compose(), this.notToBeNaN);
}

@@ -870,25 +774,30 @@ return this;

}
StringAssertion.prototype.toSnapshot = function () {
return this.obj;
};
StringAssertion.prototype.toHaveLength = function (length) {
var received = this.obj;
var received = this.obj.length;
var expected = length;
var pass = received.length === expected;
var pass = received === expected;
if (!pass) {
var message = richText()
.write(mh("toHaveLength"))
.write("Expected string to have length ", e(expected), ", instead it have length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveLength);
var message = errMsg()
.matcherHint("toHaveLength")
.info((_a = ["Expected string to have length ", ", instead it have length ", "\n"], _a.raw = ["Expected string to have length ", ", instead it have length ", "\\n"], rt(_a, e(expected), r(received))));
throw new AssertionError(message.compose(), this.toHaveLength);
}
return this;
var _a;
};
StringAssertion.prototype.notToHaveLength = function (length) {
var received = this.obj;
var received = this.obj.length;
var expected = length;
var pass = received.length !== expected;
var pass = received !== expected;
if (!pass) {
var message = richText()
.write(mh("notToHaveLength"))
.write("Expected string not to have length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveLength);
var message = errMsg()
.matcherHint("notToHaveLength")
.info((_a = ["Expected string not to have length ", "\n"], _a.raw = ["Expected string not to have length ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHaveLength);
}
return this;
var _a;
};

@@ -900,9 +809,10 @@ StringAssertion.prototype.toInclude = function (text) {

if (!pass) {
var message = richText()
.write(mh("toInclude"))
.write("Expected string to include ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toInclude);
var message = errMsg()
.matcherHint("toInclude")
.info((_a = ["Expected string to include ", "\n"], _a.raw = ["Expected string to include ", "\\n"], rt(_a, e(expected))))
.info((_b = ["Received: ", "\n"], _b.raw = ["Received: ", "\\n"], rt(_b, r(received))));
throw new AssertionError(message.compose(), this.toInclude);
}
return this;
var _a, _b;
};

@@ -914,9 +824,10 @@ StringAssertion.prototype.notToInclude = function (text) {

if (!pass) {
var message = richText()
.write(mh("notToInclude"))
.write("Expected string not to include ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToInclude);
var message = errMsg()
.matcherHint("notToInclude")
.info((_a = ["Expected string not to include ", "\n"], _a.raw = ["Expected string not to include ", "\\n"], rt(_a, e(expected))))
.info((_b = ["Received: ", "\n"], _b.raw = ["Received: ", "\\n"], rt(_b, r(received))));
throw new AssertionError(message.compose(), this.notToInclude);
}
return this;
var _a, _b;
};

@@ -928,9 +839,10 @@ StringAssertion.prototype.toMatch = function (text) {

if (!pass) {
var message = richText()
.write(mh("toMatch"))
.write("Expected string to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
var message = errMsg()
.matcherHint("toMatch")
.info((_a = ["Expected string to match ", "\n"], _a.raw = ["Expected string to match ", "\\n"], rt(_a, e(expected))))
.info((_b = ["Received: ", "\n"], _b.raw = ["Received: ", "\\n"], rt(_b, r(received))));
throw new AssertionError(message.compose(), this.toMatch);
}
return this;
var _a, _b;
};

@@ -942,9 +854,10 @@ StringAssertion.prototype.notToMatch = function (text) {

if (!pass) {
var message = richText()
.write(mh("notToMatch"))
.write("Expected string not to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
var message = errMsg()
.matcherHint("notToMatch")
.info((_a = ["Expected string not to match ", "\n"], _a.raw = ["Expected string not to match ", "\\n"], rt(_a, e(expected))))
.info((_b = ["Received: ", "\n"], _b.raw = ["Received: ", "\\n"], rt(_b, r(received))));
throw new AssertionError(message.compose(), this.notToMatch);
}
return this;
var _a, _b;
};

@@ -964,41 +877,211 @@ return StringAssertion;

tslib_1.__extends(ObjectAssertion, _super);
function ObjectAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function ObjectAssertion(obj, type) {
if (type === void 0) { type = "object"; }
var _this = _super.call(this, obj) || this;
_this.type = type;
return _this;
}
ObjectAssertion.prototype.toMatch = function (matcher) {
ObjectAssertion.prototype.toSnapshot = function () {
return toSnapshot(this.obj);
};
ObjectAssertion.prototype.toBeEqual = function (expected) {
var received = this.obj;
var expected = matcher;
var pass = matcher.match(received);
var pass = isEqual(received, expected);
if (!pass) {
var message = richText()
.write(mh("toMatch"))
.write("Expected Object to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
var message = errMsg()
.matcherHint("toBeEqual")
.info("Expected " + this.type + " to be equal (_.isEqual()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeEqual);
}
return this;
};
ObjectAssertion.prototype.notToMatch = function (matcher) {
ObjectAssertion.prototype.notToBeEqual = function (expected) {
var received = this.obj;
var expected = matcher;
var pass = !matcher.match(received);
var pass = !isEqual(received, expected);
if (!pass) {
var message = richText()
.write(mh("notToMatch"))
.write("Expected Object not to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
var message = errMsg()
.matcherHint("notToMatch")
.info("Expected " + this.type + " not to be equal (!_.isEqual()):\n")
.info(" ", e(expected), "\n");
throw new AssertionError(message.compose(), this.notToBeEqual);
}
return this;
};
ObjectAssertion.prototype.toBeEqualWith = function (expected, customizer) {
var received = this.obj;
var pass = isEqualWith(received, expected, customizer);
if (!pass) {
var message = errMsg()
.matcherHint("toBeEqualWith", "received", "expected", "customizer")
.info("Expected " + this.type + " to be equal with (_.isEqualWith()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeEqualWith);
}
return this;
};
ObjectAssertion.prototype.notToBeEqualWith = function (expected, customizer) {
var received = this.obj;
var pass = !isEqualWith(received, expected, customizer);
if (!pass) {
var message = errMsg()
.matcherHint("notToBeEqualWith", "received", "expected", "customizer")
.info("Expected " + this.type + " to be equal with (!_.isEqualWith()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToBeEqualWith);
}
return this;
};
ObjectAssertion.prototype.toMatch = function (expected) {
var received = this.obj;
var pass = isMatch(received, expected);
if (!pass) {
var message = errMsg()
.matcherHint("toMatch")
.info("Expected " + this.type + " to match (_.isMatch()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toMatch);
}
return this;
};
ObjectAssertion.prototype.notToMatch = function (expected) {
var received = this.obj;
var pass = !isMatch(received, expected);
if (!pass) {
var message = errMsg()
.matcherHint("notToMatch")
.info("Expected " + this.type + " not to match (!_.isMatch()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToMatch);
}
return this;
};
ObjectAssertion.prototype.toMatchWith = function (expected, customizer) {
var received = this.obj;
var pass = isMatchWith(received, expected, customizer);
if (!pass) {
var message = errMsg()
.matcherHint("toMatchWith", "received", "expected", "customizer")
.info("Expected " + this.type + " to match with customizer (_.isMatchWith()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toMatchWith);
}
return this;
};
ObjectAssertion.prototype.notToMatchWith = function (expected, customizer) {
var received = this.obj;
var pass = !isMatchWith(received, expected, customizer);
if (!pass) {
var message = errMsg()
.matcherHint("notToMatchWith", "received", "expected", "customizer")
.info("Expected " + this.type + " not to match with customizer (!_.isMatchWith()):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToMatchWith);
}
return this;
};
return ObjectAssertion;
}(Assertion));
export { ObjectAssertion };
var ArrayAssertion = (function (_super) {
tslib_1.__extends(ArrayAssertion, _super);
function ArrayAssertion(obj) {
return _super.call(this, obj, "array") || this;
}
ArrayAssertion.prototype.toHaveLength = function (length) {
var received = this.obj;
var expected = length;
var pass = received.length === expected;
if (!pass) {
var message = errMsg()
.matcherHint("toHaveLength")
.info((_a = ["Expected array to have a length ", " instead it have a length ", "\n"], _a.raw = ["Expected array to have a length ", " instead it have a length ", "\\n"], rt(_a, e(expected), r(received.length))));
throw new AssertionError(message.compose(), this.toHaveLength);
}
return this;
var _a;
};
ArrayAssertion.prototype.notToHaveLength = function (length) {
var received = this.obj;
var expected = length;
var pass = received.length !== expected;
if (!pass) {
var message = errMsg()
.matcherHint("notToHaveLength")
.info((_a = ["Expected array not to have a length ", "\n"], _a.raw = ["Expected array not to have a length ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHaveLength);
}
return this;
var _a;
};
ArrayAssertion.prototype.toContain = function (value) {
var received = this.obj;
var expected = value;
var pass = received.indexOf(expected) !== -1;
if (!pass) {
var message = errMsg()
.matcherHint("toContain")
.info("Expected array to contain:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toContain);
}
return this;
};
ArrayAssertion.prototype.notToContain = function (value) {
var received = this.obj;
var expected = value;
var pass = received.indexOf(expected) === -1;
if (!pass) {
var message = errMsg()
.matcherHint("notToContain")
.info("Expected array not to contain:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToContain);
}
return this;
};
return ArrayAssertion;
}(ObjectAssertion));
export { ArrayAssertion };
var DateAssertion = (function (_super) {
tslib_1.__extends(DateAssertion, _super);
function DateAssertion(obj) {
return _super.call(this, obj, "Date") || this;
}
return DateAssertion;
}(ObjectAssertion));
export { DateAssertion };
var ErrorAssertion = (function (_super) {
tslib_1.__extends(ErrorAssertion, _super);
function ErrorAssertion(obj) {
return _super.call(this, obj, "Error") || this;
}
return ErrorAssertion;
}(ObjectAssertion));
export { ErrorAssertion };
var RegExpAssertion = (function (_super) {
tslib_1.__extends(RegExpAssertion, _super);
function RegExpAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function RegExpAssertion(obj) {
return _super.call(this, obj, "RegExp") || this;
}
RegExpAssertion.prototype.toSnapshot = function () {
return this.obj.valueOf();
return this.obj.valueOf().toString();
};

@@ -1010,9 +1093,10 @@ RegExpAssertion.prototype.toTest = function (text) {

if (!pass) {
var message = richText()
.write(mh("toTest"))
.write("Expected RegExp to test ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toTest);
var message = errMsg()
.matcherHint("toTest")
.info((_a = ["Expected RegExp to test ", "\n"], _a.raw = ["Expected RegExp to test ", "\\n"], rt(_a, e(expected))))
.info((_b = ["Received: ", "\n"], _b.raw = ["Received: ", "\\n"], rt(_b, r(received))));
throw new AssertionError(message.compose(), this.toTest);
}
return this;
var _a, _b;
};

@@ -1024,41 +1108,44 @@ RegExpAssertion.prototype.notToTest = function (text) {

if (!pass) {
var message = richText()
.write(mh("notToTest"))
.write("Expected RegExp not to test ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToTest);
var message = errMsg()
.matcherHint("notToTest")
.info((_a = ["Expected RegExp not to test ", "\n"], _a.raw = ["Expected RegExp not to test ", "\\n"], rt(_a, e(expected))))
.info((_b = ["Received: ", "\n"], _b.raw = ["Received: ", "\\n"], rt(_b, r(received))));
throw new AssertionError(message.compose(), this.notToTest);
}
return this;
var _a, _b;
};
return RegExpAssertion;
}(Assertion));
}(ObjectAssertion));
export { RegExpAssertion };
var MapAssertion = (function (_super) {
tslib_1.__extends(MapAssertion, _super);
function MapAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function MapAssertion(obj) {
return _super.call(this, obj, "Map") || this;
}
MapAssertion.prototype.toHaveSize = function (size) {
var received = this.obj;
var received = this.obj.size;
var expected = size;
var pass = received.size === expected;
var pass = received === expected;
if (!pass) {
var message = richText()
.write(mh("toHaveSize"))
.write("Expected Map to have size ", e(expected), ", instead it have size ", r(received.size), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveSize);
var message = errMsg()
.matcherHint("toHaveSize")
.info((_a = ["Expected Map to have size ", ", instead it have size ", "\n"], _a.raw = ["Expected Map to have size ", ", instead it have size ", "\\n"], rt(_a, e(expected), r(received))));
throw new AssertionError(message.compose(), this.toHaveSize);
}
return this;
var _a;
};
MapAssertion.prototype.notToHaveSize = function (size) {
var received = this.obj;
var received = this.obj.size;
var expected = size;
var pass = received.size !== expected;
var pass = received !== expected;
if (!pass) {
var message = richText()
.write(mh("notToHaveSize"))
.write("Expected Map not to have size ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveSize);
var message = errMsg()
.matcherHint("notToHaveSize")
.info((_a = ["Expected Map not to have size ", "\n"], _a.raw = ["Expected Map not to have size ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHaveSize);
}
return this;
var _a;
};

@@ -1070,8 +1157,9 @@ MapAssertion.prototype.toHave = function (key) {

if (!pass) {
var message = richText()
.write(mh("toHave"))
.write("Expected Map to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
var message = errMsg()
.matcherHint("toHave")
.info((_a = ["Expected Map to have ", "\n"], _a.raw = ["Expected Map to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.toHave);
}
return this;
var _a;
};

@@ -1083,40 +1171,43 @@ MapAssertion.prototype.notToHave = function (key) {

if (!pass) {
var message = richText()
.write(mh("notToHave"))
.write("Expected Map not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
var message = errMsg()
.matcherHint("notToHave")
.info((_a = ["Expected Map not to have ", "\n"], _a.raw = ["Expected Map not to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHave);
}
return this;
var _a;
};
return MapAssertion;
}(Assertion));
}(ObjectAssertion));
export { MapAssertion };
var SetAssertion = (function (_super) {
tslib_1.__extends(SetAssertion, _super);
function SetAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function SetAssertion(obj) {
return _super.call(this, obj, "Set") || this;
}
SetAssertion.prototype.toHaveSize = function (size) {
var received = this.obj;
var received = this.obj.size;
var expected = size;
var pass = received.size === expected;
var pass = received === expected;
if (!pass) {
var message = richText()
.write(mh("toHaveSize"))
.write("Expected Set to have size ", e(expected), ", instead it have size ", r(received.size), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveSize);
var message = errMsg()
.matcherHint("toHaveSize")
.info((_a = ["Expected Set to have size ", ", instead it have size ", "\n"], _a.raw = ["Expected Set to have size ", ", instead it have size ", "\\n"], rt(_a, e(expected), r(received))));
throw new AssertionError(message.compose(), this.toHaveSize);
}
return this;
var _a;
};
SetAssertion.prototype.notToHaveSize = function (size) {
var received = this.obj;
var received = this.obj.size;
var expected = size;
var pass = received.size !== expected;
var pass = received !== expected;
if (!pass) {
var message = richText()
.write(mh("notToHaveSize"))
.write("Expected Set not to have size ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveSize);
var message = errMsg()
.matcherHint("notToHaveSize")
.info((_a = ["Expected Set not to have size ", "\n"], _a.raw = ["Expected Set not to have size ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHaveSize);
}
return this;
var _a;
};

@@ -1128,8 +1219,9 @@ SetAssertion.prototype.toHave = function (value) {

if (!pass) {
var message = richText()
.write(mh("toHave"))
.write("Expected Set to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
var message = errMsg()
.matcherHint("toHave")
.info((_a = ["Expected Set to have ", "\n"], _a.raw = ["Expected Set to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.toHave);
}
return this;
var _a;
};

@@ -1141,16 +1233,17 @@ SetAssertion.prototype.notToHave = function (value) {

if (!pass) {
var message = richText()
.write(mh("notToHave"))
.write("Expected Set not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
var message = errMsg()
.matcherHint("notToHave")
.info((_a = ["Expected Set not to have ", "\n"], _a.raw = ["Expected Set not to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHave);
}
return this;
var _a;
};
return SetAssertion;
}(Assertion));
}(ObjectAssertion));
export { SetAssertion };
var WeakMapAssertion = (function (_super) {
tslib_1.__extends(WeakMapAssertion, _super);
function WeakMapAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function WeakMapAssertion(obj) {
return _super.call(this, obj, "WeakMap") || this;
}

@@ -1162,8 +1255,9 @@ WeakMapAssertion.prototype.toHave = function (key) {

if (!pass) {
var message = richText()
.write(mh("toHave"))
.write("Expected WeakMap to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
var message = errMsg()
.matcherHint("toHave")
.info((_a = ["Expected WeakMap to have ", "\n"], _a.raw = ["Expected WeakMap to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.toHave);
}
return this;
var _a;
};

@@ -1175,16 +1269,17 @@ WeakMapAssertion.prototype.notToHave = function (key) {

if (!pass) {
var message = richText()
.write(mh("notToHave"))
.write("Expected WeakMap not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
var message = errMsg()
.matcherHint("notToHave")
.info((_a = ["Expected WeakMap not to have ", "\n"], _a.raw = ["Expected WeakMap not to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHave);
}
return this;
var _a;
};
return WeakMapAssertion;
}(Assertion));
}(ObjectAssertion));
export { WeakMapAssertion };
var WeakSetAssertion = (function (_super) {
tslib_1.__extends(WeakSetAssertion, _super);
function WeakSetAssertion() {
return _super !== null && _super.apply(this, arguments) || this;
function WeakSetAssertion(obj) {
return _super.call(this, obj, "WeakSet") || this;
}

@@ -1196,8 +1291,9 @@ WeakSetAssertion.prototype.toHave = function (value) {

if (!pass) {
var message = richText()
.write(mh("toHave"))
.write("Expected WeakSet to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
var message = errMsg()
.matcherHint("toHave")
.info((_a = ["Expected WeakSet to have ", "\n"], _a.raw = ["Expected WeakSet to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.toHave);
}
return this;
var _a;
};

@@ -1209,11 +1305,12 @@ WeakSetAssertion.prototype.notToHave = function (value) {

if (!pass) {
var message = richText()
.write(mh("notToHave"))
.write("Expected WeakSet not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
var message = errMsg()
.matcherHint("notToHave")
.info((_a = ["Expected WeakSet not to have ", "\n"], _a.raw = ["Expected WeakSet not to have ", "\\n"], rt(_a, e(expected))));
throw new AssertionError(message.compose(), this.notToHave);
}
return this;
var _a;
};
return WeakSetAssertion;
}(Assertion));
}(ObjectAssertion));
export { WeakSetAssertion };

@@ -1220,0 +1317,0 @@ var assertionFactory = function (obj) {

@@ -0,2 +1,4 @@

import * as tslib_1 from "tslib";
import * as prettyFormat from "pretty-format";
import { RichTextWriter, annotate } from "rtext-writer";
var PLUGINS = [

@@ -29,105 +31,109 @@ prettyFormat.plugins.HTMLElement,

}
var NUMBERS = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
];
export function pluralize(word, count) {
var result = ((count < NUMBERS.length) ? NUMBERS[count] : count.toString()) + " " + word;
if (count === 1) {
return result;
}
return result + "s";
export function leftPad(p, s) {
return s.replace(/^/gm, p);
}
export function matcherHint(writer, matcherName, received, expected, secondArgument) {
if (received === void 0) { received = "received"; }
if (expected === void 0) { expected = "expected"; }
writer
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(")." + matcherName + "(")
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
writer
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
writer
.write(")")
.write("\n\n")
.end("matcherHint");
/**
* hl is a function that highlights matched text regions. By default it highlights trailing whitespaces.
*
* @param text Raw text.
* @param regexp RegExp matcher.
* @param type Annotation type.
* @returns Rich Text.
*/
export function hl(text, regexp, type) {
if (regexp === void 0) { regexp = /\s+$/gm; }
if (type === void 0) { type = "highlight"; }
return annotate(text, regexp, type);
}
export function highlightTrailingWhitespace(text) {
var re = /\s+$/gm;
var match = re.exec(text);
var annotations = [];
while (match !== null) {
var start = match.index;
var end = start + match[0].length;
annotations.push({
type: "trailingWhitespace",
start: start,
end: end,
data: undefined,
key: undefined,
});
match = re.exec(text);
}
return {
text: text,
annotations: annotations.length === 0 ? undefined : annotations,
};
}
export function printReceived(writer, value, raw) {
writer
.begin("received")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("received");
}
export function printExpected(writer, value, raw) {
writer
.begin("expected")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("expected");
}
export function printInfo(writer, s) {
writer
.begin("info")
.write(s)
.end("info");
}
export function mh(matcherName, received, expected, secondArgument) {
if (received === void 0) { received = "received"; }
if (expected === void 0) { expected = "expected"; }
return function (w) {
matcherHint(w, matcherName, received, expected, secondArgument);
};
}
export function r(value, raw) {
return function (w) {
printReceived(w, value, raw);
return function (writer) {
writer
.begin("received")
.write(raw ? value : hl(stringify(value)))
.end("received");
};
}
export function e(value, raw) {
return function (w) {
printExpected(w, value, raw);
return function (writer) {
writer
.begin("expected")
.write(raw ? value : hl(stringify(value)))
.end("expected");
};
}
export function info(s) {
return function (w) {
printInfo(w, s);
var ErrorMessageWriter = (function (_super) {
tslib_1.__extends(ErrorMessageWriter, _super);
function ErrorMessageWriter() {
return _super !== null && _super.apply(this, arguments) || this;
}
ErrorMessageWriter.prototype.matcherHint = function (matcherName, received, expected, secondArgument) {
if (received === void 0) { received = "received"; }
if (expected === void 0) { expected = "expected"; }
this
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(")." + matcherName + "(")
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
this
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
this
.write(")")
.write("\n\n")
.end("matcherHint");
return this;
};
ErrorMessageWriter.prototype.hint = function () {
var ws = [];
for (var _i = 0; _i < arguments.length; _i++) {
ws[_i] = arguments[_i];
}
(_a = this
.continue("hint")).write.apply(_a, ws).end("hint");
return this;
var _a;
};
ErrorMessageWriter.prototype.info = function () {
var ws = [];
for (var _i = 0; _i < arguments.length; _i++) {
ws[_i] = arguments[_i];
}
(_a = this
.continue("info")).write.apply(_a, ws).end("info");
return this;
var _a;
};
ErrorMessageWriter.prototype.diff = function () {
var ws = [];
for (var _i = 0; _i < arguments.length; _i++) {
ws[_i] = arguments[_i];
}
(_a = this
.begin("diff")).write.apply(_a, ws).end("diff");
return this;
var _a;
};
ErrorMessageWriter.prototype.received = function (value) {
this
.begin("received")
.write(hl(stringify(value)))
.end("received");
return this;
};
ErrorMessageWriter.prototype.expected = function (value) {
this
.begin("expected")
.write(hl(stringify(value)))
.end("expected");
return this;
};
return ErrorMessageWriter;
}(RichTextWriter));
export { ErrorMessageWriter };
export function errMsg() {
return new ErrorMessageWriter();
}
//# sourceMappingURL=stringify.js.map
import * as prettyFormat from "pretty-format";
import { richText } from "rtext-writer";
import { diffLines, structuredPatch } from "diff";
import { highlightTrailingWhitespace } from "./stringify";
const NO_DIFF_MESSAGE = richText()
.begin("hint")
.write("Compared values have no visual difference.")
.end("hint")
import { errMsg, hl } from "./stringify";
const NO_DIFF_MESSAGE = errMsg()
.hint("Compared values have no visual difference.")
.compose();
const SIMILAR_MESSAGE = richText()
.begin("hint")
.write("Compared values serialize to the same structure.\n")
.write("Printing internal object structure without calling `toJSON` instead.")
.end("hint")
const SIMILAR_MESSAGE = errMsg()
.hint("Compared values serialize to the same structure.\n")
.hint("Printing internal object structure without calling `toJSON` instead.")
.compose();

@@ -43,3 +39,3 @@ const DIFF_CONTEXT = 5;

while (j < lines.length) {
result.begin("+").write("+ ", highlightTrailingWhitespace(lines[j++]), "\n").end("+");
result.begin("+").write("+ ", hl(lines[j++]), "\n").end("+");
}

@@ -50,3 +46,3 @@ }

while (j < lines.length) {
result.begin("-").write("- ", highlightTrailingWhitespace(lines[j++]), "\n").end("-");
result.begin("-").write("- ", hl(lines[j++]), "\n").end("-");
}

@@ -56,3 +52,3 @@ }

while (j < lines.length) {
result.write(" ", highlightTrailingWhitespace(lines[j++]), "\n");
result.write(" ", hl(lines[j++]), "\n");
}

@@ -106,3 +102,3 @@ }

const line = lines[j];
const highlightedLined = highlightTrailingWhitespace(line);
const highlightedLined = hl(line);
const added = line.charCodeAt(0) === 43; // +

@@ -109,0 +105,0 @@ const removed = line.charCodeAt(0) === 45; // -

const HasErrorCaptureStackTrace = Error.captureStackTrace !== undefined;
export class AssertionError extends Error {
constructor(message, actual, expected, ssf) {
constructor(message, ssf) {
super(message.text);
this.actual = actual;
if (expected !== undefined) {
this.expected = expected;
}
this.$$type = "AssertionError";
if (message.annotations !== null) {

@@ -10,0 +7,0 @@ this.annotations = message.annotations;

export { AssertionError } from "./error";
export { Matcher, m } from "./matcher";
export { ErrorMessageWriter, errMsg, r, e, hl, stringify } from "./stringify";
export { diff } from "./diff";
import { rt } from "rtext-writer";
import { AssertionError } from "./error";
import { diff } from "./diff";
import { richText } from "rtext-writer";
import { AssertionError } from "./error";
import { mh, r, e } from "./stringify";
import { Matcher, matchArray, matchException } from "./matcher";
import { errMsg, r, e } from "./stringify";
import { toSnapshot } from "./snapshot";
import { isEqual, isEqualWith, isMatch, isMatchWith } from "lodash";
export class Assertion {

@@ -13,3 +15,3 @@ constructor(obj) {

toSnapshot() {
return this.obj;
return this.obj.toString();
}

@@ -19,3 +21,3 @@ assert(expr, message, expected, actual) {

if (pass === false) {
throw new AssertionError(message(expected, actual), actual, expected, this.assert);
throw new AssertionError(message(expected, actual), this.assert);
}

@@ -28,7 +30,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeFalsy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, false, this.toBeFalsy);
const message = errMsg()
.matcherHint("toBeFalsy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeFalsy);
}

@@ -41,7 +43,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeTruthy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeTruthy);
const message = errMsg()
.matcherHint("toBeTruthy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeTruthy);
}

@@ -56,16 +58,12 @@ return this;

const diffText = diff(expected, received);
const message = richText()
.write(mh("toBe"))
.write("Expected value to be (strict equality ===):\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
const message = errMsg()
.matcherHint("toBe")
.info("Expected value to be (strict equality ===):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
if (diffText !== null) {
message
.begin("diff")
.write("\n", "Difference:\n\n")
.write(diffText)
.end("diff");
message.diff("\nDifference:\n\n", diffText);
}
throw new AssertionError(message.compose(), received, expected, this.toBe);
throw new AssertionError(message.compose(), this.toBe);
}

@@ -79,9 +77,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBe"))
.write("Expected value not to be (strict inequality !==):\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, expected, this.toBe);
const message = errMsg()
.matcherHint("notToBe")
.info("Expected value not to be (strict inequality !==):\n")
.info(" ", e(expected), "\n");
throw new AssertionError(message.compose(), this.toBe);
}

@@ -94,7 +90,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeNull", "received", ""))
.write("Expected value to be null, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeNull);
const message = errMsg()
.matcherHint("toBeNull", "received", "")
.info("Expected value to be null, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeNull);
}

@@ -107,6 +103,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeNull", "received", ""))
.write("Expected value not to be null\n");
throw new AssertionError(message.compose(), received, true, this.notToBeNull);
const message = errMsg()
.matcherHint("notToBeNull", "received", "")
.info("Expected value not to be null\n");
throw new AssertionError(message.compose(), this.notToBeNull);
}

@@ -119,7 +115,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeUndefined", "received", ""))
.write("Expected value to be undefined, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeUndefined);
const message = errMsg()
.matcherHint("toBeUndefined", "received", "")
.info("Expected value to be undefined, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeUndefined);
}

@@ -132,6 +128,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeUndefined", "received", ""))
.write("Expected value not to be undefined\n");
throw new AssertionError(message.compose(), received, true, this.notToBeUndefined);
const message = errMsg()
.matcherHint("notToBeUndefined", "received", "")
.info("Expected value not to be undefined\n");
throw new AssertionError(message.compose(), this.notToBeUndefined);
}

@@ -144,7 +140,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeObject", "received", ""))
.write("Expected value to be an object, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeObject);
const message = errMsg()
.matcherHint("toBeObject", "received", "")
.info("Expected value to be an object, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeObject);
}

@@ -157,7 +153,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeArray", "received", ""))
.write("Expected value to be an array, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeArray);
const message = errMsg()
.matcherHint("toBeArray", "received", "")
.info("Expected value to be an array, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeArray);
}

@@ -170,7 +166,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeBoolean", "received", ""))
.write("Expected value to be a boolean, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeBoolean);
const message = errMsg()
.matcherHint("toBeBoolean", "received", "")
.info("Expected value to be a boolean, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeBoolean);
}

@@ -183,7 +179,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeNumber", "received", ""))
.write("Expected value to be a number, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeNumber);
const message = errMsg()
.matcherHint("toBeNumber", "received", "")
.info("Expected value to be a number, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeNumber);
}

@@ -196,7 +192,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeString", "received", ""))
.write("Expected value to be a string, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeString);
const message = errMsg()
.matcherHint("toBeString", "received", "")
.info("Expected value to be a string, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeString);
}

@@ -209,7 +205,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeFunction", "received", ""))
.write("Expected value to be a function, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeFunction);
const message = errMsg()
.matcherHint("toBeFunction", "received", "")
.info("Expected value to be a function, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeFunction);
}

@@ -222,7 +218,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeSymbol", "received", ""))
.write("Expected value to be a symbol, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeSymbol);
const message = errMsg()
.matcherHint("toBeSymbol", "received", "")
.info("Expected value to be a symbol, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeSymbol);
}

@@ -235,7 +231,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeDate", "received", ""))
.write("Expected value to be a Date, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeDate);
const message = errMsg()
.matcherHint("toBeDate", "received", "")
.info("Expected value to be a Date, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeDate);
}

@@ -248,7 +244,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeRegExp", "received", ""))
.write("Expected value to be a RegExp, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeRegExp);
const message = errMsg()
.matcherHint("toBeRegExp", "received", "")
.info("Expected value to be a RegExp, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeRegExp);
}

@@ -261,7 +257,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeError", "received", ""))
.write("Expected value to be an Error, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeError);
const message = errMsg()
.matcherHint("toBeError", "received", "")
.info("Expected value to be an Error, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeError);
}

@@ -274,7 +270,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeMap", "received", ""))
.write("Expected value to be a Map, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeMap);
const message = errMsg()
.matcherHint("toBeMap", "received", "")
.info("Expected value to be a Map, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeMap);
}

@@ -287,7 +283,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeWeakMap", "received", ""))
.write("Expected value to be a WeakMap, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeWeakMap);
const message = errMsg()
.matcherHint("toBeWeakMap", "received", "")
.info("Expected value to be a WeakMap, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeWeakMap);
}

@@ -300,7 +296,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeSet", "received", ""))
.write("Expected value to be a Set, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeSet);
const message = errMsg()
.matcherHint("toBeSet", "received", "")
.info("Expected value to be a Set, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeSet);
}

@@ -313,7 +309,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeWeakSet", "received", ""))
.write("Expected value to be a WeakSet, instead received:\n")
.write(" ", r(received));
throw new AssertionError(message.compose(), received, true, this.toBeWeakSet);
const message = errMsg()
.matcherHint("toBeWeakSet", "received", "")
.info("Expected value to be a WeakSet, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeWeakSet);
}

@@ -327,9 +323,9 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeInstanceOf"))
.write("Expected value to be an instance of:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeInstanceOf);
const message = errMsg()
.matcherHint("toBeInstanceOf")
.info("Expected value to be an instance of:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeInstanceOf);
}

@@ -343,9 +339,9 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeInstanceOf"))
.write("Expected value not to be an instance of:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToBeInstanceOf);
const message = errMsg()
.matcherHint("notToBeInstanceOf")
.info("Expected value not to be an instance of:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToBeInstanceOf);
}

@@ -355,90 +351,2 @@ return this;

}
export class ArrayAssertion extends Assertion {
toHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveLength"))
.write("Expected array to have a length ", e(expected), ", instead it have a length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveLength);
}
return this;
}
notToHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveLength"))
.write("Expected array not to have a length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveLength);
}
return this;
}
toContain(value) {
const received = this.obj;
const expected = value;
const pass = expected instanceof Matcher ?
received.some((i) => expected.match(i)) :
received.indexOf(expected) !== -1;
if (!pass) {
const message = richText()
.write(mh("toContain"))
.write("Expected array to include:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toContain);
}
return this;
}
notToContain(value) {
const received = this.obj;
const expected = value;
const pass = expected instanceof Matcher ?
!received.some((i) => expected.match(i)) :
received.indexOf(expected) === -1;
if (!pass) {
const message = richText()
.write(mh("notToContain"))
.write("Expected array not to contain:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToContain);
}
return this;
}
toMatch(match) {
const received = this.obj;
const expected = match;
const pass = matchArray(received, expected);
if (!pass) {
const message = richText()
.write(mh("toMatch"))
.write("Expected array to match:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
}
return this;
}
notToMatch(match) {
const received = this.obj;
const expected = match;
const pass = !matchArray(received, expected);
if (!pass) {
const message = richText()
.write(mh("notToMatch"))
.write("Expected array not to match:\n")
.write(" ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
}
return this;
}
}
export class NullAssertion extends Assertion {

@@ -456,16 +364,31 @@ constructor() {

}
export class DateAssertion extends Assertion {
function matchException(a, b) {
if (typeof b === "string") {
if (typeof a === "string" && a.indexOf(b) !== -1) {
return true;
}
else if (a instanceof Error && a.message.indexOf(b) !== -1) {
return true;
}
}
else {
if (b instanceof Error) {
return a.constructor === b.constructor || a instanceof b.constructor;
}
else if (b.prototype instanceof Error || b === Error) {
return a.constructor === b || a instanceof b;
}
}
return false;
}
export class ErrorAssertion extends Assertion {
}
export class FunctionAssertion extends Assertion {
toHaveArgumentsLength(length) {
const received = this.obj;
const received = this.obj.length;
const expected = length;
const pass = received.length === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveArgumentsLength"))
.write("Expected function to have arguments length ", e(expected), ", instead it have arguments length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveArgumentsLength);
const message = errMsg()
.matcherHint("toHaveArgumentsLength")
.info(rt `Expected function to have arguments length ${e(expected)}, instead it have length ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toHaveArgumentsLength);
}

@@ -479,6 +402,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToHaveLength"))
.write("Expected function not to have arguments length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveArgumentsLength);
const message = errMsg()
.matcherHint("notToHaveLength")
.info(rt `Expected function not to have arguments length ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHaveArgumentsLength);
}

@@ -488,5 +411,3 @@ return this;

toThrow(expected) {
const received = this.obj;
let pass = false;
let throwed;
try {

@@ -496,4 +417,3 @@ this.obj();

catch (e) {
throwed = e;
if (expected !== undefined && matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = true;

@@ -503,6 +423,6 @@ }

if (!pass) {
const message = richText()
.write(mh("toThrow"))
.write("Expected function to throw an exception ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toThrow);
const message = errMsg()
.matcherHint("toThrow")
.info(rt `Expected function to throw an exception ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.toThrow);
}

@@ -512,5 +432,3 @@ return this;

notToThrow(expected) {
const received = this.obj;
let pass = true;
let throwed;
try {

@@ -520,4 +438,3 @@ this.obj();

catch (e) {
throwed = e;
if (expected !== undefined && matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = false;

@@ -527,6 +444,6 @@ }

if (!pass) {
const message = richText()
.write(mh("notToThrow"))
.write("Expected function not to throw an exception ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToThrow);
const message = errMsg()
.matcherHint("notToThrow")
.info(rt `Expected function not to throw an exception ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToThrow);
}

@@ -547,9 +464,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be approximately equal to ", e(b), ", intstead received ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeApproximatelyEqual);
const message = errMsg()
.matcherHint("toBeApproximatelyEqual", "received", "expected", "epsilon")
.hint(rt `abs(${rA} - ${eB}) <= (abs(${rA}) < abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt `Expected number to be approximately equal to ${e(b)}, intstead received ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeApproximatelyEqual);
}

@@ -565,9 +480,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be approximately equal to ", e(b), ", instead received ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeApproximatelyEqual);
const message = errMsg()
.matcherHint("notToBeApproximatelyEqual", "received", "expected", "epsilon")
.hint(rt `!(abs(${rA} - ${eB}) <= (abs(${rA}) < abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rt `Expected number not to be approximately equal to ${e(b)}, instead received ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeApproximatelyEqual);
}

@@ -583,9 +496,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be essentially equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeEssentiallyEqual);
const message = errMsg()
.matcherHint("toBeEssentiallyEqual", "received", "expected", "epsilon")
.hint(rt `abs(${rA} - ${eB}) <= (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt `Expected number to be essentially equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeEssentiallyEqual);
}

@@ -601,9 +512,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be essentially equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeEssentiallyEqual);
const message = errMsg()
.matcherHint("notToBeEssentiallyEqual", "received", "expected", "epsilon")
.hint(rt `!(abs(${rA} - ${eB}) <= (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}) \n\n`)
.info(rt `Expected number not to be essentially equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeEssentiallyEqual);
}

@@ -619,9 +528,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", rA, " - ", eB, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeDefinetelyGreaterThan);
const message = errMsg()
.matcherHint("toBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint(rt `(${rA} - ${eB}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt `Expected number to be definetely greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeDefinetelyGreaterThan);
}

@@ -637,9 +544,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", rA, " - ", eB, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeDefinetelyGreaterThan);
const message = errMsg()
.matcherHint("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint(rt `!((${rA} - ${eB}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rt `Expected number not to be definetely greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeDefinetelyGreaterThan);
}

@@ -655,9 +560,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", eB, " - ", rA, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeDefinetelyLessThan);
const message = errMsg()
.matcherHint("toBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint(rt `(${eB} - ${rA}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt `Expected number to be definetely less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeDefinetelyLessThan);
}

@@ -673,9 +576,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", eB, " - ", rA, ") > ", "(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeDefinetelyLessThan);
const message = errMsg()
.matcherHint("notToBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint(rt `!((${eB} - ${rA}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rt `Expected number not to be definetely less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeDefinetelyLessThan);
}

@@ -689,6 +590,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeGreaterThan"))
.write("Expected number to be greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeGreaterThan);
const message = errMsg()
.matcherHint("toBeGreaterThan")
.info(rt `Expected number to be greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeGreaterThan);
}

@@ -702,6 +603,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeGreaterThan"))
.write("Expected number not to be greater than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeGreaterThan);
const message = errMsg()
.matcherHint("notToBeGreaterThan")
.info(rt `Expected number not to be greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeGreaterThan);
}

@@ -715,6 +616,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeGreaterThanOrEqual"))
.write("Expected number to be greater than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeGreaterThanOrEqual);
const message = errMsg()
.matcherHint("toBeGreaterThanOrEqual")
.info(rt `Expected number to be greater than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeGreaterThanOrEqual);
}

@@ -728,6 +629,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeGreaterThanOrEqual"))
.write("Expected number not to be greater than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeGreaterThanOrEqual);
const message = errMsg()
.matcherHint("notToBeGreaterThanOrEqual")
.info(rt `Expected number not to be greater than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeGreaterThanOrEqual);
}

@@ -741,6 +642,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeLessThan"))
.write("Expected number to be less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeLessThan);
const message = errMsg()
.matcherHint("toBeLessThan")
.info(rt `Expected number to be less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeLessThan);
}

@@ -754,6 +655,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeLessThan"))
.write("Expected number not to be less than ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeLessThan);
const message = errMsg()
.matcherHint("notToBeLessThan")
.info(rt `Expected number not to be less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeLessThan);
}

@@ -767,6 +668,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeLessThanOrEqual"))
.write("Expected number to be less than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.toBeLessThanOrEqual);
const message = errMsg()
.matcherHint("toBeLessThanOrEqual")
.info(rt `Expected number to be less than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeLessThanOrEqual);
}

@@ -780,6 +681,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeLessThanOrEqual"))
.write("Expected number not to be less than or equal to ", e(b), ", instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, b, this.notToBeLessThanOrEqual);
const message = errMsg()
.matcherHint("notToBeLessThanOrEqual")
.info(rt `Expected number not to be less than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.notToBeLessThanOrEqual);
}

@@ -792,6 +693,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeNaN", "received", ""))
.write("Expected number to be NaN, instead received: ", r(a), "\n");
throw new AssertionError(message.compose(), a, NaN, this.toBeNaN);
const message = errMsg()
.matcherHint("toBeNaN", "received", "")
.info(rt `Expected number to be NaN, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), this.toBeNaN);
}

@@ -804,6 +705,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToBeNaN", "received", ""))
.write("Expected number not to be NaN\n");
throw new AssertionError(message.compose(), a, NaN, this.notToBeNaN);
const message = errMsg()
.matcherHint("notToBeNaN", "received", "")
.info("Expected number not to be NaN\n");
throw new AssertionError(message.compose(), this.notToBeNaN);
}

@@ -814,11 +715,14 @@ return this;

export class StringAssertion extends Assertion {
toSnapshot() {
return this.obj;
}
toHaveLength(length) {
const received = this.obj;
const received = this.obj.length;
const expected = length;
const pass = received.length === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveLength"))
.write("Expected string to have length ", e(expected), ", instead it have length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveLength);
const message = errMsg()
.matcherHint("toHaveLength")
.info(rt `Expected string to have length ${e(expected)}, instead it have length ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toHaveLength);
}

@@ -828,10 +732,10 @@ return this;

notToHaveLength(length) {
const received = this.obj;
const received = this.obj.length;
const expected = length;
const pass = received.length !== expected;
const pass = received !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveLength"))
.write("Expected string not to have length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveLength);
const message = errMsg()
.matcherHint("notToHaveLength")
.info(rt `Expected string not to have length ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHaveLength);
}

@@ -845,7 +749,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toInclude"))
.write("Expected string to include ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toInclude);
const message = errMsg()
.matcherHint("toInclude")
.info(rt `Expected string to include ${e(expected)}\n`)
.info(rt `Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toInclude);
}

@@ -859,7 +763,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToInclude"))
.write("Expected string not to include ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToInclude);
const message = errMsg()
.matcherHint("notToInclude")
.info(rt `Expected string not to include ${e(expected)}\n`)
.info(rt `Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), this.notToInclude);
}

@@ -873,7 +777,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toMatch"))
.write("Expected string to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
const message = errMsg()
.matcherHint("toMatch")
.info(rt `Expected string to match ${e(expected)}\n`)
.info(rt `Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toMatch);
}

@@ -887,7 +791,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToMatch"))
.write("Expected string not to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
const message = errMsg()
.matcherHint("notToMatch")
.info(rt `Expected string not to match ${e(expected)}\n`)
.info(rt `Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), this.notToMatch);
}

@@ -900,32 +804,195 @@ return this;

export class ObjectAssertion extends Assertion {
toMatch(matcher) {
constructor(obj, type = "object") {
super(obj);
this.type = type;
}
toSnapshot() {
return toSnapshot(this.obj);
}
toBeEqual(expected) {
const received = this.obj;
const expected = matcher;
const pass = matcher.match(received);
const pass = isEqual(received, expected);
if (!pass) {
const message = richText()
.write(mh("toMatch"))
.write("Expected Object to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
const message = errMsg()
.matcherHint("toBeEqual")
.info(`Expected ${this.type} to be equal (_.isEqual()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeEqual);
}
return this;
}
notToMatch(matcher) {
notToBeEqual(expected) {
const received = this.obj;
const expected = matcher;
const pass = !matcher.match(received);
const pass = !isEqual(received, expected);
if (!pass) {
const message = richText()
.write(mh("notToMatch"))
.write("Expected Object not to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
const message = errMsg()
.matcherHint("notToMatch")
.info(`Expected ${this.type} not to be equal (!_.isEqual()):\n`)
.info(" ", e(expected), "\n");
throw new AssertionError(message.compose(), this.notToBeEqual);
}
return this;
}
toBeEqualWith(expected, customizer) {
const received = this.obj;
const pass = isEqualWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("toBeEqualWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to be equal with (_.isEqualWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeEqualWith);
}
return this;
}
notToBeEqualWith(expected, customizer) {
const received = this.obj;
const pass = !isEqualWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("notToBeEqualWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to be equal with (!_.isEqualWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToBeEqualWith);
}
return this;
}
toMatch(expected) {
const received = this.obj;
const pass = isMatch(received, expected);
if (!pass) {
const message = errMsg()
.matcherHint("toMatch")
.info(`Expected ${this.type} to match (_.isMatch()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toMatch);
}
return this;
}
notToMatch(expected) {
const received = this.obj;
const pass = !isMatch(received, expected);
if (!pass) {
const message = errMsg()
.matcherHint("notToMatch")
.info(`Expected ${this.type} not to match (!_.isMatch()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToMatch);
}
return this;
}
toMatchWith(expected, customizer) {
const received = this.obj;
const pass = isMatchWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("toMatchWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to match with customizer (_.isMatchWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toMatchWith);
}
return this;
}
notToMatchWith(expected, customizer) {
const received = this.obj;
const pass = !isMatchWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("notToMatchWith", "received", "expected", "customizer")
.info(`Expected ${this.type} not to match with customizer (!_.isMatchWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToMatchWith);
}
return this;
}
}
export class RegExpAssertion extends Assertion {
export class ArrayAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "array");
}
toHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length === expected;
if (!pass) {
const message = errMsg()
.matcherHint("toHaveLength")
.info(rt `Expected array to have a length ${e(expected)} instead it have a length ${r(received.length)}\n`);
throw new AssertionError(message.compose(), this.toHaveLength);
}
return this;
}
notToHaveLength(length) {
const received = this.obj;
const expected = length;
const pass = received.length !== expected;
if (!pass) {
const message = errMsg()
.matcherHint("notToHaveLength")
.info(rt `Expected array not to have a length ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHaveLength);
}
return this;
}
toContain(value) {
const received = this.obj;
const expected = value;
const pass = received.indexOf(expected) !== -1;
if (!pass) {
const message = errMsg()
.matcherHint("toContain")
.info("Expected array to contain:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toContain);
}
return this;
}
notToContain(value) {
const received = this.obj;
const expected = value;
const pass = received.indexOf(expected) === -1;
if (!pass) {
const message = errMsg()
.matcherHint("notToContain")
.info("Expected array not to contain:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToContain);
}
return this;
}
}
export class DateAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Date");
}
}
export class ErrorAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Error");
}
}
export class RegExpAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "RegExp");
}
toSnapshot() {
return this.obj.valueOf();
return this.obj.valueOf().toString();
}

@@ -937,7 +1004,7 @@ toTest(text) {

if (!pass) {
const message = richText()
.write(mh("toTest"))
.write("Expected RegExp to test ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toTest);
const message = errMsg()
.matcherHint("toTest")
.info(rt `Expected RegExp to test ${e(expected)}\n`)
.info(rt `Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toTest);
}

@@ -951,7 +1018,7 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToTest"))
.write("Expected RegExp not to test ", e(expected), "\n")
.write("Received: ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToTest);
const message = errMsg()
.matcherHint("notToTest")
.info(rt `Expected RegExp not to test ${e(expected)}\n`)
.info(rt `Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), this.notToTest);
}

@@ -961,12 +1028,15 @@ return this;

}
export class MapAssertion extends Assertion {
export class MapAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Map");
}
toHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveSize"))
.write("Expected Map to have size ", e(expected), ", instead it have size ", r(received.size), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveSize);
const message = errMsg()
.matcherHint("toHaveSize")
.info(rt `Expected Map to have size ${e(expected)}, instead it have size ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toHaveSize);
}

@@ -976,10 +1046,10 @@ return this;

notToHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size !== expected;
const pass = received !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveSize"))
.write("Expected Map not to have size ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveSize);
const message = errMsg()
.matcherHint("notToHaveSize")
.info(rt `Expected Map not to have size ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHaveSize);
}

@@ -993,6 +1063,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected Map to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
const message = errMsg()
.matcherHint("toHave")
.info(rt `Expected Map to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1006,6 +1076,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected Map not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
const message = errMsg()
.matcherHint("notToHave")
.info(rt `Expected Map not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1015,12 +1085,15 @@ return this;

}
export class SetAssertion extends Assertion {
export class SetAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "Set");
}
toHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveSize"))
.write("Expected Set to have size ", e(expected), ", instead it have size ", r(received.size), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveSize);
const message = errMsg()
.matcherHint("toHaveSize")
.info(rt `Expected Set to have size ${e(expected)}, instead it have size ${r(received)}\n`);
throw new AssertionError(message.compose(), this.toHaveSize);
}

@@ -1030,10 +1103,10 @@ return this;

notToHaveSize(size) {
const received = this.obj;
const received = this.obj.size;
const expected = size;
const pass = received.size !== expected;
const pass = received !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveSize"))
.write("Expected Set not to have size ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveSize);
const message = errMsg()
.matcherHint("notToHaveSize")
.info(rt `Expected Set not to have size ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHaveSize);
}

@@ -1047,6 +1120,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected Set to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
const message = errMsg()
.matcherHint("toHave")
.info(rt `Expected Set to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1060,6 +1133,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected Set not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
const message = errMsg()
.matcherHint("notToHave")
.info(rt `Expected Set not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1069,3 +1142,6 @@ return this;

}
export class WeakMapAssertion extends Assertion {
export class WeakMapAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "WeakMap");
}
toHave(key) {

@@ -1076,6 +1152,6 @@ const received = this.obj;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected WeakMap to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
const message = errMsg()
.matcherHint("toHave")
.info(rt `Expected WeakMap to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1089,6 +1165,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected WeakMap not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
const message = errMsg()
.matcherHint("notToHave")
.info(rt `Expected WeakMap not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1098,3 +1174,6 @@ return this;

}
export class WeakSetAssertion extends Assertion {
export class WeakSetAssertion extends ObjectAssertion {
constructor(obj) {
super(obj, "WeakSet");
}
toHave(value) {

@@ -1105,6 +1184,6 @@ const received = this.obj;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected WeakSet to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.toHave);
const message = errMsg()
.matcherHint("toHave")
.info(rt `Expected WeakSet to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1118,6 +1197,6 @@ return this;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected WeakSet not to have ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHave);
const message = errMsg()
.matcherHint("notToHave")
.info(rt `Expected WeakSet not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1124,0 +1203,0 @@ return this;

import * as prettyFormat from "pretty-format";
import { RichTextWriter, annotate } from "rtext-writer";
const PLUGINS = [

@@ -28,101 +29,90 @@ prettyFormat.plugins.HTMLElement,

}
const NUMBERS = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
];
export function pluralize(word, count) {
const result = ((count < NUMBERS.length) ? NUMBERS[count] : count.toString()) + " " + word;
if (count === 1) {
return result;
}
return result + "s";
export function leftPad(p, s) {
return s.replace(/^/gm, p);
}
export function matcherHint(writer, matcherName, received = "received", expected = "expected", secondArgument) {
writer
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(`).${matcherName}(`)
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
writer
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
writer
.write(")")
.write("\n\n")
.end("matcherHint");
/**
* hl is a function that highlights matched text regions. By default it highlights trailing whitespaces.
*
* @param text Raw text.
* @param regexp RegExp matcher.
* @param type Annotation type.
* @returns Rich Text.
*/
export function hl(text, regexp = /\s+$/gm, type = "highlight") {
return annotate(text, regexp, type);
}
export function highlightTrailingWhitespace(text) {
const re = /\s+$/gm;
let match = re.exec(text);
const annotations = [];
while (match !== null) {
const start = match.index;
const end = start + match[0].length;
annotations.push({
type: "trailingWhitespace",
start: start,
end: end,
data: undefined,
key: undefined,
});
match = re.exec(text);
}
return {
text: text,
annotations: annotations.length === 0 ? undefined : annotations,
};
}
export function printReceived(writer, value, raw) {
writer
.begin("received")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("received");
}
export function printExpected(writer, value, raw) {
writer
.begin("expected")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("expected");
}
export function printInfo(writer, s) {
writer
.begin("info")
.write(s)
.end("info");
}
export function mh(matcherName, received = "received", expected = "expected", secondArgument) {
return function (w) {
matcherHint(w, matcherName, received, expected, secondArgument);
};
}
export function r(value, raw) {
return function (w) {
printReceived(w, value, raw);
return function (writer) {
writer
.begin("received")
.write(raw ? value : hl(stringify(value)))
.end("received");
};
}
export function e(value, raw) {
return function (w) {
printExpected(w, value, raw);
return function (writer) {
writer
.begin("expected")
.write(raw ? value : hl(stringify(value)))
.end("expected");
};
}
export function info(s) {
return function (w) {
printInfo(w, s);
};
export class ErrorMessageWriter extends RichTextWriter {
matcherHint(matcherName, received = "received", expected = "expected", secondArgument) {
this
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(`).${matcherName}(`)
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
this
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
this
.write(")")
.write("\n\n")
.end("matcherHint");
return this;
}
hint(...ws) {
this
.continue("hint")
.write(...ws)
.end("hint");
return this;
}
info(...ws) {
this
.continue("info")
.write(...ws)
.end("info");
return this;
}
diff(...ws) {
this
.begin("diff")
.write(...ws)
.end("diff");
return this;
}
received(value) {
this
.begin("received")
.write(hl(stringify(value)))
.end("received");
return this;
}
expected(value) {
this
.begin("expected")
.write(hl(stringify(value)))
.end("expected");
return this;
}
}
export function errMsg() {
return new ErrorMessageWriter();
}
//# sourceMappingURL=stringify.js.map
import { RichText, RichTextAnnotation } from "rtext";
export declare class AssertionError extends Error {
readonly actual: any;
readonly expected?: any;
readonly $$type: "AssertionError";
readonly annotations?: RichTextAnnotation[];
constructor(message: RichText, actual: any, expected?: any, ssf?: Function);
constructor(message: RichText, ssf?: Function);
}

@@ -0,3 +1,5 @@

/// <reference types="lodash" />
export { AssertionError } from "./error";
export { Matcher, m } from "./matcher";
export { ErrorMessageWriter, errMsg, r, e, hl, stringify } from "./stringify";
export { diff } from "./diff";
/**

@@ -8,16 +10,19 @@ * TypeScript doesn't allow augmentation of re-exported modules:

import { RichText } from "rtext";
import { Matcher } from "./matcher";
import { isMatchCustomizer } from "lodash";
export declare class Assertion<T> {
obj: T;
readonly obj: T;
constructor(obj: T);
toSnapshot(): any;
assert<E>(expr: (() => boolean) | boolean, message: (expected: E, actual?: T) => RichText, expected: E, actual?: T): Assertion<T>;
toBeFalsy(): Assertion<T>;
toBeTruthy(): Assertion<T>;
toBe(value: T): Assertion<T>;
notToBe(value: T): Assertion<T>;
toSnapshot(): string | {
lang?: string;
code: string;
};
assert<E>(expr: (() => boolean) | boolean, message: (expected: E, actual?: T) => RichText, expected: E, actual?: T): this;
toBeFalsy(): this;
toBeTruthy(): this;
toBe(value: T): this;
notToBe(value: T): this;
toBeNull(): NullAssertion;
notToBeNull(): NullAssertion;
notToBeNull(): this;
toBeUndefined(): UndefinedAssertion;
notToBeUndefined(): UndefinedAssertion;
notToBeUndefined(): this;
toBeObject<O extends object>(): ObjectAssertion<O>;

@@ -37,13 +42,5 @@ toBeArray<U>(): ArrayAssertion<U>;

toBeWeakSet<V = any>(): WeakSetAssertion<V>;
toBeInstanceOf(type: Function): Assertion<T>;
notToBeInstanceOf(type: Function): Assertion<T>;
toBeInstanceOf(type: Function): this;
notToBeInstanceOf(type: Function): this;
}
export declare class ArrayAssertion<T> extends Assertion<T[]> {
toHaveLength(length: number): ArrayAssertion<T>;
notToHaveLength(length: number): ArrayAssertion<T>;
toContain(value: T | Matcher): ArrayAssertion<T>;
notToContain(value: T | Matcher): ArrayAssertion<T>;
toMatch(match: T[]): ArrayAssertion<T>;
notToMatch(match: T[]): ArrayAssertion<T>;
}
export declare class NullAssertion extends Assertion<null> {

@@ -57,39 +54,36 @@ constructor();

}
export declare class DateAssertion extends Assertion<Date> {
}
export declare class ErrorAssertion<E extends Error> extends Assertion<E> {
}
export declare class FunctionAssertion extends Assertion<Function> {
toHaveArgumentsLength(length: number): FunctionAssertion;
notToHaveArgumentsLength(length: number): FunctionAssertion;
toThrow<E extends Error | ErrorConstructor>(expected?: E): FunctionAssertion;
notToThrow<E extends Error | ErrorConstructor>(expected?: E): FunctionAssertion;
toHaveArgumentsLength(length: number): this;
notToHaveArgumentsLength(length: number): this;
toThrow<E extends Error | ErrorConstructor>(expected?: string | E): this;
notToThrow<E extends Error | ErrorConstructor>(expected?: string | E): this;
}
export declare class NumberAssertion extends Assertion<number> {
toBeApproximatelyEqual(number: number, epsilon?: number): NumberAssertion;
notToBeApproximatelyEqual(number: number, epsilon?: number): NumberAssertion;
toBeEssentiallyEqual(number: number, epsilon?: number): NumberAssertion;
notToBeEssentiallyEqual(number: number, epsilon?: number): NumberAssertion;
toBeDefinetelyGreaterThan(number: number, epsilon?: number): NumberAssertion;
notToBeDefinetelyGreaterThan(number: number, epsilon?: number): NumberAssertion;
toBeDefinetelyLessThan(number: number, epsilon?: number): NumberAssertion;
notToBeDefinetelyLessThan(number: number, epsilon?: number): NumberAssertion;
toBeGreaterThan(number: number): NumberAssertion;
notToBeGreaterThan(number: number): NumberAssertion;
toBeGreaterThanOrEqual(number: number): NumberAssertion;
notToBeGreaterThanOrEqual(number: number): NumberAssertion;
toBeLessThan(number: number): NumberAssertion;
notToBeLessThan(number: number): NumberAssertion;
toBeLessThanOrEqual(number: number): NumberAssertion;
notToBeLessThanOrEqual(number: number): NumberAssertion;
toBeNaN(): NumberAssertion;
notToBeNaN(): NumberAssertion;
toBeApproximatelyEqual(number: number, epsilon?: number): this;
notToBeApproximatelyEqual(number: number, epsilon?: number): this;
toBeEssentiallyEqual(number: number, epsilon?: number): this;
notToBeEssentiallyEqual(number: number, epsilon?: number): this;
toBeDefinetelyGreaterThan(number: number, epsilon?: number): this;
notToBeDefinetelyGreaterThan(number: number, epsilon?: number): this;
toBeDefinetelyLessThan(number: number, epsilon?: number): this;
notToBeDefinetelyLessThan(number: number, epsilon?: number): this;
toBeGreaterThan(number: number): this;
notToBeGreaterThan(number: number): this;
toBeGreaterThanOrEqual(number: number): this;
notToBeGreaterThanOrEqual(number: number): this;
toBeLessThan(number: number): this;
notToBeLessThan(number: number): this;
toBeLessThanOrEqual(number: number): this;
notToBeLessThanOrEqual(number: number): this;
toBeNaN(): this;
notToBeNaN(): this;
}
export declare class StringAssertion extends Assertion<string> {
toHaveLength(length: number): StringAssertion;
notToHaveLength(length: number): StringAssertion;
toInclude(text: string): StringAssertion;
notToInclude(text: string): StringAssertion;
toMatch(text: string | RegExp): StringAssertion;
notToMatch(text: string | RegExp): StringAssertion;
toSnapshot(): string;
toHaveLength(length: number): this;
notToHaveLength(length: number): this;
toInclude(text: string): this;
notToInclude(text: string): this;
toMatch(text: string | RegExp): this;
notToMatch(text: string | RegExp): this;
}

@@ -99,37 +93,57 @@ export declare class SymbolAssertion extends Assertion<Symbol> {

export declare class ObjectAssertion<T extends object> extends Assertion<T> {
toMatch(matcher: Matcher): ObjectAssertion<T>;
notToMatch(matcher: Matcher): ObjectAssertion<T>;
readonly type: string;
constructor(obj: T, type?: string);
toSnapshot(): string;
toBeEqual(expected: T): this;
notToBeEqual(expected: T): this;
toBeEqualWith(expected: T, customizer: isMatchCustomizer): this;
notToBeEqualWith(expected: T, customizer: isMatchCustomizer): this;
toMatch(expected: any): this;
notToMatch(expected: any): this;
toMatchWith(expected: any, customizer: isMatchCustomizer): this;
notToMatchWith(expected: any, customizer: isMatchCustomizer): this;
}
export declare const enum RegExpFlags {
Global = 1,
IgnoreCase = 2,
Multiline = 4,
Unicode = 8,
Sticky = 16,
export declare class ArrayAssertion<T> extends ObjectAssertion<T[]> {
constructor(obj: T[]);
toHaveLength(length: number): this;
notToHaveLength(length: number): this;
toContain(value: T): this;
notToContain(value: T): this;
}
export declare class RegExpAssertion extends Assertion<RegExp> {
toSnapshot(): Object;
toTest(text: string): RegExpAssertion;
notToTest(text: string): RegExpAssertion;
export declare class DateAssertion extends ObjectAssertion<Date> {
constructor(obj: Date);
}
export declare class MapAssertion<K, V> extends Assertion<Map<K, V>> {
toHaveSize(size: number): MapAssertion<K, V>;
notToHaveSize(size: number): MapAssertion<K, V>;
toHave(key: K): MapAssertion<K, V>;
notToHave(key: K): MapAssertion<K, V>;
export declare class ErrorAssertion<E extends Error> extends ObjectAssertion<E> {
constructor(obj: E);
}
export declare class SetAssertion<V> extends Assertion<Set<V>> {
toHaveSize(size: number): SetAssertion<V>;
notToHaveSize(size: number): SetAssertion<V>;
toHave(value: V): SetAssertion<V>;
notToHave(value: V): SetAssertion<V>;
export declare class RegExpAssertion extends ObjectAssertion<RegExp> {
constructor(obj: RegExp);
toSnapshot(): string;
toTest(text: string): this;
notToTest(text: string): this;
}
export declare class WeakMapAssertion<K extends object, V> extends Assertion<WeakMap<K, V>> {
toHave(key: K): WeakMapAssertion<K, V>;
notToHave(key: K): WeakMapAssertion<K, V>;
export declare class MapAssertion<K, V> extends ObjectAssertion<Map<K, V>> {
constructor(obj: Map<K, V>);
toHaveSize(size: number): this;
notToHaveSize(size: number): this;
toHave(key: K): this;
notToHave(key: K): this;
}
export declare class WeakSetAssertion<V> extends Assertion<WeakSet<V>> {
toHave(value: V): WeakSetAssertion<V>;
notToHave(value: V): WeakSetAssertion<V>;
export declare class SetAssertion<V> extends ObjectAssertion<Set<V>> {
constructor(obj: Set<V>);
toHaveSize(size: number): this;
notToHaveSize(size: number): this;
toHave(value: V): this;
notToHave(value: V): this;
}
export declare class WeakMapAssertion<K extends object, V> extends ObjectAssertion<WeakMap<K, V>> {
constructor(obj: WeakMap<K, V>);
toHave(key: K): this;
notToHave(key: K): this;
}
export declare class WeakSetAssertion<V> extends ObjectAssertion<WeakSet<V>> {
constructor(obj: WeakSet<V>);
toHave(value: V): this;
notToHave(value: V): this;
}
export declare type AssertionFactory<T extends Assertion<any>> = (obj: any) => T | undefined;

@@ -136,0 +150,0 @@ export declare function addAssertionType<T>(factory: (obj: any) => T | undefined): void;

import { RichText } from "rtext";
import { RichTextWriter } from "rtext-writer";
export declare function stringify(object: any, maxDepth?: number): string;
export declare function pluralize(word: string, count: number): string;
export declare function matcherHint(writer: RichTextWriter, matcherName: string, received?: string, expected?: string, secondArgument?: string): void;
export declare function highlightTrailingWhitespace(text: string): RichText;
export declare function printReceived(writer: RichTextWriter, value: any, raw?: boolean): void;
export declare function printExpected(writer: RichTextWriter, value: any, raw?: boolean): void;
export declare function printInfo(writer: RichTextWriter, s: string): void;
export declare function mh(matcherName: string, received?: string, expected?: string, secondArgument?: string): (w: RichTextWriter) => void;
export declare function r(value: any, raw?: boolean): (w: RichTextWriter) => void;
export declare function e(value: any, raw?: boolean): (w: RichTextWriter) => void;
export declare function info(s: string): (w: RichTextWriter) => void;
export declare function leftPad(p: string, s: string): string;
/**
* hl is a function that highlights matched text regions. By default it highlights trailing whitespaces.
*
* @param text Raw text.
* @param regexp RegExp matcher.
* @param type Annotation type.
* @returns Rich Text.
*/
export declare function hl(text: string, regexp?: RegExp, type?: string): RichText;
export declare function r(value: any, raw?: boolean): (writer: RichTextWriter) => void;
export declare function e(value: any, raw?: boolean): (writer: RichTextWriter) => void;
export declare class ErrorMessageWriter extends RichTextWriter {
matcherHint(matcherName: string, received?: string, expected?: string, secondArgument?: string): this;
hint(...ws: Array<string | RichText | ((w: RichTextWriter) => void)>): this;
info(...ws: Array<string | RichText | ((w: RichTextWriter) => void)>): this;
diff(...ws: Array<string | RichText | ((w: RichTextWriter) => void)>): this;
received(value: any): this;
expected(value: any): this;
}
export declare function errMsg(): ErrorMessageWriter;
{
"name": "iko",
"version": "0.3.0",
"version": "0.4.0",
"main": "dist/cjs/index.js",

@@ -49,6 +49,9 @@ "module": "dist/es5/index.js",

"diff": "^3.3.0",
"lodash": "^4.17.4",
"pretty-format": "^20.0.3",
"rtext": "^0.1.0"
},
"devDependencies": {}
"devDependencies": {
"@types/lodash": "^4.14.71"
}
}

@@ -6,2 +6,4 @@ # TypeScript Assertion Library

![iko screenshot][screenshot]
## Features

@@ -12,2 +14,3 @@

- Side-effect free assertions
- Using [lodash](https://lodash.com) deep equality and matching functions
- Snapshot testing in a browser

@@ -52,2 +55,10 @@

export class MyTypeAssertion extends ObjectAssertion<MyType> {
constructor(obj: MyType) {
super(obj, "MyType");
}
// ...
}
addAssertionType((obj: any) => {

@@ -59,6 +70,2 @@ if (typeof obj === "object" && obj instanceof MyType) {

}):
export class MyTypeAssertion extends Assertion<MyType> {
// ...
}
```

@@ -69,3 +76,3 @@

```ts
import { Assertion, mh, r } from "iko";
import { Assertion, errMsg, r } from "iko";
import { richText } from "rtext-writer";

@@ -85,6 +92,6 @@

if (!pass) {
const message = richText()
.write(mh("toBeMyType", "received", ""))
.write("Expected Object to have MyType type:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeMyType", "received", "")
.info("Expected Object to have MyType type:\n")
.info(" ", r(received), "\n");

@@ -98,4 +105,161 @@ throw new AssertionError(message.compose(), received, "MyType", this.toBeMyType);

## API
```ts
class Assertion<T> {
readonly obj: T;
constructor(obj: T);
toSnapshot(): string | { lang?: string, code: string };
assert<E>(
expr: (() => boolean) | boolean,
message: (expected: E, actual?: T) => RichText,
expected: E,
actual?: T,
): this;
toBeFalsy(): this;
toBeTruthy(): this;
toBe(value: T): this;
toBeNull(): NullAssertion;
toBeUndefined(): UndefinedAssertion;
toBeInstanceOf(type: Function): this;
notToBe(value: T): this;
notToBeNull(): this;
notToBeUndefined(): this;
notToBeInstanceOf(type: Function): this;
toBeObject<O extends object>(): ObjectAssertion<O>;
toBeArray<U>(): ArrayAssertion<U>;
toBeBoolean(): BooleanAssertion;
toBeNumber(): NumberAssertion;
toBeString(): StringAssertion;
toBeFunction(): FunctionAssertion;
toBeSymbol(): SymbolAssertion;
toBeDate(): DateAssertion;
toBeRegExp(): RegExpAssertion;
toBeError<E extends Error>(): ErrorAssertion<E>;
toBeMap<K extends object = any, V = any>(): MapAssertion<K, V>;
toBeWeakMap<K extends object = any, V = any>(): WeakMapAssertion<K, V>;
toBeSet<V = any>(): SetAssertion<V>;
toBeWeakSet<V = any>(): WeakSetAssertion<V>;
}
class NullAssertion extends Assertion<null> { }
class UndefinedAssertion extends Assertion<undefined> { }
class BooleanAssertion extends Assertion<boolean> { }
class FunctionAssertion extends Assertion<Function> {
toHaveArgumentsLength(length: number): this;
toThrow<E extends Error | ErrorConstructor>(expected?: string | E): this;
notToHaveArgumentsLength(length: number): this;
notToThrow<E extends Error | ErrorConstructor>(expected?: string | E): this;
}
class NumberAssertion extends Assertion<number> {
toBeApproximatelyEqual(number: number, epsilon = Number.EPSILON): this;
toBeEssentiallyEqual(number: number, epsilon = Number.EPSILON): this;
toBeDefinetelyGreaterThan(number: number, epsilon = Number.EPSILON): this;
toBeDefinetelyLessThan(number: number, epsilon = Number.EPSILON): this;
toBeGreaterThan(number: number): this;
toBeGreaterThanOrEqual(number: number): this;
toBeLessThan(number: number): this;
toBeLessThanOrEqual(number: number): this;
toBeNaN(): this;
notToBeApproximatelyEqual(number: number, epsilon = Number.EPSILON): this;
notToBeEssentiallyEqual(number: number, epsilon = Number.EPSILON): this;
notToBeDefinetelyGreaterThan(number: number, epsilon = Number.EPSILON): this;
notToBeDefinetelyLessThan(number: number, epsilon = Number.EPSILON): this;
notToBeGreaterThan(number: number): this;
notToBeGreaterThanOrEqual(number: number): this;
notToBeLessThan(number: number): this;
notToBeLessThanOrEqual(number: number): this;
notToBeNaN(): this;
}
class StringAssertion extends Assertion<string> {
toHaveLength(length: number): this;
toInclude(text: string): this;
toMatch(text: string | RegExp): this;
notToHaveLength(length: number): this;
notToInclude(text: string): this;
notToMatch(text: string | RegExp): this;
}
class SymbolAssertion extends Assertion<Symbol> { }
class ObjectAssertion<T extends object> extends Assertion<T> {
readonly type: string;
constructor(obj: T, type = "object");
toBeEqual(expected: T): this;
toBeEqualWith(expected: T, customizer: isMatchCustomizer): this;
toMatch(expected: any): this;
toMatchWith(expected: any, customizer: isMatchCustomizer): this;
notToBeEqual(expected: T): this;
notToBeEqualWith(expected: T, customizer: isMatchCustomizer): this;
notToMatch(expected: any): this;
notToMatchWith(expected: any, customizer: isMatchCustomizer): this;
}
class ArrayAssertion<T> extends ObjectAssertion<T[]> {
toHaveLength(length: number): this;
notToHaveLength(length: number): this;
toContain(value: T): this;
notToContain(value: T): this;
}
class DateAssertion extends ObjectAssertion<Date> { }
class ErrorAssertion<E extends Error> extends ObjectAssertion<E> { }
class RegExpAssertion extends ObjectAssertion<RegExp> {
toTest(text: string): this;
notToTest(text: string): this;
}
class MapAssertion<K, V> extends ObjectAssertion<Map<K, V>> {
toHaveSize(size: number): this;
toHave(key: K): this;
notToHaveSize(size: number): this;
notToHave(key: K): this;
}
class SetAssertion<V> extends ObjectAssertion<Set<V>> {
toHaveSize(size: number): this;
toHave(value: V): this;
notToHaveSize(size: number): this;
notToHave(value: V): this;
}
class WeakMapAssertion<K extends object, V> extends ObjectAssertion<WeakMap<K, V>> {
toHave(key: K): this;
notToHave(key: K): this;
}
class WeakSetAssertion<V> extends ObjectAssertion<WeakSet<V>> {
toHave(value: V): this;
notToHave(value: V): this;
}
```
## License
MIT
[screenshot]: https://localvoid.github.io/karma-snapshot/images/example.png "iko screenshot"

@@ -5,15 +5,11 @@ import * as prettyFormat from "pretty-format";

import { diffLines, structuredPatch, IHunk } from "diff";
import { highlightTrailingWhitespace } from "./stringify";
import { errMsg, hl } from "./stringify";
const NO_DIFF_MESSAGE = richText()
.begin("hint")
.write("Compared values have no visual difference.")
.end("hint")
const NO_DIFF_MESSAGE = errMsg()
.hint("Compared values have no visual difference.")
.compose();
const SIMILAR_MESSAGE = richText()
.begin("hint")
.write("Compared values serialize to the same structure.\n")
.write("Printing internal object structure without calling `toJSON` instead.")
.end("hint")
const SIMILAR_MESSAGE = errMsg()
.hint("Compared values serialize to the same structure.\n")
.hint("Printing internal object structure without calling `toJSON` instead.")
.compose();

@@ -53,3 +49,3 @@

while (j < lines.length) {
result.begin("+").write("+ ", highlightTrailingWhitespace(lines[j++]), "\n").end("+");
result.begin("+").write("+ ", hl(lines[j++]), "\n").end("+");
}

@@ -59,7 +55,7 @@ } else if (part.removed) {

while (j < lines.length) {
result.begin("-").write("- ", highlightTrailingWhitespace(lines[j++]), "\n").end("-");
result.begin("-").write("- ", hl(lines[j++]), "\n").end("-");
}
} else {
while (j < lines.length) {
result.write(" ", highlightTrailingWhitespace(lines[j++]), "\n");
result.write(" ", hl(lines[j++]), "\n");
}

@@ -121,3 +117,3 @@ }

const line = lines[j];
const highlightedLined = highlightTrailingWhitespace(line);
const highlightedLined = hl(line);
const added = line.charCodeAt(0) === 43; // +

@@ -124,0 +120,0 @@ const removed = line.charCodeAt(0) === 45; // -

@@ -6,12 +6,8 @@ import { RichText, RichTextAnnotation } from "rtext";

export class AssertionError extends Error {
readonly actual: any;
readonly expected?: any;
readonly $$type: "AssertionError";
readonly annotations?: RichTextAnnotation[];
constructor(message: RichText, actual: any, expected?: any, ssf?: Function) {
constructor(message: RichText, ssf?: Function) {
super(message.text);
this.actual = actual;
if (expected !== undefined) {
this.expected = expected;
}
this.$$type = "AssertionError";
if (message.annotations !== null) {

@@ -18,0 +14,0 @@ this.annotations = message.annotations;

export { AssertionError } from "./error";
export { Matcher, m } from "./matcher";
import { diff } from "./diff";
export { ErrorMessageWriter, errMsg, r, e, hl, stringify } from "./stringify";
export { diff } from "./diff";

@@ -10,9 +10,11 @@ /**

import { RichText } from "rtext";
import { richText } from "rtext-writer";
import { rt } from "rtext-writer";
import { AssertionError } from "./error";
import { mh, r, e } from "./stringify";
import { Matcher, matchArray, matchException } from "./matcher";
import { diff } from "./diff";
import { errMsg, r, e } from "./stringify";
import { toSnapshot } from "./snapshot";
import { isEqual, isEqualWith, isMatch, isMatchWith, isMatchCustomizer } from "lodash";
export class Assertion<T> {
obj: T;
readonly obj: T;

@@ -23,4 +25,4 @@ constructor(obj: T) {

toSnapshot(): any {
return this.obj;
toSnapshot(): string | { lang?: string, code: string } {
return this.obj.toString();
}

@@ -33,6 +35,6 @@

actual?: T,
): Assertion<T> {
): this {
const pass = ((typeof expr === "function") ? expr() : expr) === true;
if (pass === false) {
throw new AssertionError(message(expected, actual), actual, expected, this.assert);
throw new AssertionError(message(expected, actual), this.assert);
}

@@ -42,12 +44,12 @@ return this;

toBeFalsy(): Assertion<T> {
toBeFalsy(): this {
const received = this.obj;
const pass = !received;
if (!pass) {
const message = richText()
.write(mh("toBeFalsy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeFalsy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, false, this.toBeFalsy);
throw new AssertionError(message.compose(), this.toBeFalsy);
}

@@ -57,12 +59,12 @@ return this;

toBeTruthy(): Assertion<T> {
toBeTruthy(): this {
const received = this.obj;
const pass = !!received;
if (!pass) {
const message = richText()
.write(mh("toBeTruthy", "received", ""))
.write("Expected value to be truthy, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeTruthy", "received", "")
.info("Expected value to be truthy, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeTruthy);
throw new AssertionError(message.compose(), this.toBeTruthy);
}

@@ -72,3 +74,3 @@ return this;

toBe(value: T): Assertion<T> {
toBe(value: T): this {
const expected = value;

@@ -79,17 +81,13 @@ const received = this.obj;

const diffText = diff(expected, received);
const message = richText()
.write(mh("toBe"))
.write("Expected value to be (strict equality ===):\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
const message = errMsg()
.matcherHint("toBe")
.info("Expected value to be (strict equality ===):\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
if (diffText !== null) {
message
.begin("diff")
.write("\n", "Difference:\n\n")
.write(diffText)
.end("diff");
message.diff("\nDifference:\n\n", diffText);
}
throw new AssertionError(message.compose(), received, expected, this.toBe);
throw new AssertionError(message.compose(), this.toBe);
}

@@ -99,3 +97,3 @@ return this;

notToBe(value: T): Assertion<T> {
notToBe(value: T): this {
const expected = value;

@@ -105,10 +103,8 @@ const received = this.obj;

if (!pass) {
const message = richText()
.write(mh("notToBe"))
.write("Expected value not to be (strict inequality !==):\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
const message = errMsg()
.matcherHint("notToBe")
.info("Expected value not to be (strict inequality !==):\n")
.info(" ", e(expected), "\n");
throw new AssertionError(message.compose(), received, expected, this.toBe);
throw new AssertionError(message.compose(), this.toBe);
}

@@ -122,8 +118,8 @@ return this;

if (!pass) {
const message = richText()
.write(mh("toBeNull", "received", ""))
.write("Expected value to be null, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeNull", "received", "")
.info("Expected value to be null, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeNull);
throw new AssertionError(message.compose(), this.toBeNull);
}

@@ -133,13 +129,13 @@ return this as any as NullAssertion;

notToBeNull(): NullAssertion {
notToBeNull(): this {
const received = this.obj;
const pass = received !== null;
if (!pass) {
const message = richText()
.write(mh("notToBeNull", "received", ""))
.write("Expected value not to be null\n");
const message = errMsg()
.matcherHint("notToBeNull", "received", "")
.info("Expected value not to be null\n");
throw new AssertionError(message.compose(), received, true, this.notToBeNull);
throw new AssertionError(message.compose(), this.notToBeNull);
}
return this as any as NullAssertion;
return this;
}

@@ -151,8 +147,8 @@

if (!pass) {
const message = richText()
.write(mh("toBeUndefined", "received", ""))
.write("Expected value to be undefined, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeUndefined", "received", "")
.info("Expected value to be undefined, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeUndefined);
throw new AssertionError(message.compose(), this.toBeUndefined);
}

@@ -162,13 +158,13 @@ return this as any as UndefinedAssertion;

notToBeUndefined(): UndefinedAssertion {
notToBeUndefined(): this {
const received = this.obj;
const pass = received !== undefined;
if (!pass) {
const message = richText()
.write(mh("notToBeUndefined", "received", ""))
.write("Expected value not to be undefined\n");
const message = errMsg()
.matcherHint("notToBeUndefined", "received", "")
.info("Expected value not to be undefined\n");
throw new AssertionError(message.compose(), received, true, this.notToBeUndefined);
throw new AssertionError(message.compose(), this.notToBeUndefined);
}
return this as any as UndefinedAssertion;
return this;
}

@@ -180,8 +176,8 @@

if (!pass) {
const message = richText()
.write(mh("toBeObject", "received", ""))
.write("Expected value to be an object, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeObject", "received", "")
.info("Expected value to be an object, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeObject);
throw new AssertionError(message.compose(), this.toBeObject);
}

@@ -195,8 +191,8 @@ return this as any as ObjectAssertion<O>;

if (!pass) {
const message = richText()
.write(mh("toBeArray", "received", ""))
.write("Expected value to be an array, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeArray", "received", "")
.info("Expected value to be an array, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeArray);
throw new AssertionError(message.compose(), this.toBeArray);
}

@@ -210,8 +206,8 @@ return this as any as ArrayAssertion<U>;

if (!pass) {
const message = richText()
.write(mh("toBeBoolean", "received", ""))
.write("Expected value to be a boolean, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeBoolean", "received", "")
.info("Expected value to be a boolean, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeBoolean);
throw new AssertionError(message.compose(), this.toBeBoolean);
}

@@ -225,8 +221,8 @@ return this as any as BooleanAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeNumber", "received", ""))
.write("Expected value to be a number, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeNumber", "received", "")
.info("Expected value to be a number, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeNumber);
throw new AssertionError(message.compose(), this.toBeNumber);
}

@@ -240,8 +236,8 @@ return this as any as NumberAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeString", "received", ""))
.write("Expected value to be a string, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeString", "received", "")
.info("Expected value to be a string, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeString);
throw new AssertionError(message.compose(), this.toBeString);
}

@@ -255,8 +251,8 @@ return this as any as StringAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeFunction", "received", ""))
.write("Expected value to be a function, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeFunction", "received", "")
.info("Expected value to be a function, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeFunction);
throw new AssertionError(message.compose(), this.toBeFunction);
}

@@ -270,8 +266,8 @@ return this as any as FunctionAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeSymbol", "received", ""))
.write("Expected value to be a symbol, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeSymbol", "received", "")
.info("Expected value to be a symbol, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeSymbol);
throw new AssertionError(message.compose(), this.toBeSymbol);
}

@@ -285,8 +281,8 @@ return this as any as SymbolAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeDate", "received", ""))
.write("Expected value to be a Date, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeDate", "received", "")
.info("Expected value to be a Date, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeDate);
throw new AssertionError(message.compose(), this.toBeDate);
}

@@ -300,8 +296,8 @@ return this as any as DateAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeRegExp", "received", ""))
.write("Expected value to be a RegExp, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeRegExp", "received", "")
.info("Expected value to be a RegExp, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeRegExp);
throw new AssertionError(message.compose(), this.toBeRegExp);
}

@@ -315,8 +311,8 @@ return this as any as RegExpAssertion;

if (!pass) {
const message = richText()
.write(mh("toBeError", "received", ""))
.write("Expected value to be an Error, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeError", "received", "")
.info("Expected value to be an Error, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeError);
throw new AssertionError(message.compose(), this.toBeError);
}

@@ -330,8 +326,8 @@ return this as any as ErrorAssertion<E>;

if (!pass) {
const message = richText()
.write(mh("toBeMap", "received", ""))
.write("Expected value to be a Map, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeMap", "received", "")
.info("Expected value to be a Map, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeMap);
throw new AssertionError(message.compose(), this.toBeMap);
}

@@ -345,8 +341,8 @@ return this as any as MapAssertion<K, V>;

if (!pass) {
const message = richText()
.write(mh("toBeWeakMap", "received", ""))
.write("Expected value to be a WeakMap, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeWeakMap", "received", "")
.info("Expected value to be a WeakMap, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeWeakMap);
throw new AssertionError(message.compose(), this.toBeWeakMap);
}

@@ -360,8 +356,8 @@ return this as any as WeakMapAssertion<K, V>;

if (!pass) {
const message = richText()
.write(mh("toBeSet", "received", ""))
.write("Expected value to be a Set, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeSet", "received", "")
.info("Expected value to be a Set, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeSet);
throw new AssertionError(message.compose(), this.toBeSet);
}

@@ -375,8 +371,8 @@ return this as any as SetAssertion<V>;

if (!pass) {
const message = richText()
.write(mh("toBeWeakSet", "received", ""))
.write("Expected value to be a WeakSet, instead received:\n")
.write(" ", r(received));
const message = errMsg()
.matcherHint("toBeWeakSet", "received", "")
.info("Expected value to be a WeakSet, instead received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeWeakSet);
throw new AssertionError(message.compose(), this.toBeWeakSet);
}

@@ -386,3 +382,3 @@ return this as any as WeakSetAssertion<V>;

toBeInstanceOf(type: Function): Assertion<T> {
toBeInstanceOf(type: Function): this {
const received = this.obj;

@@ -392,10 +388,10 @@ const expected = type;

if (!pass) {
const message = richText()
.write(mh("toBeInstanceOf"))
.write("Expected value to be an instance of:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
const message = errMsg()
.matcherHint("toBeInstanceOf")
.info("Expected value to be an instance of:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toBeInstanceOf);
throw new AssertionError(message.compose(), this.toBeInstanceOf);
}

@@ -405,3 +401,3 @@ return this;

notToBeInstanceOf(type: Function): Assertion<T> {
notToBeInstanceOf(type: Function): this {
const received = this.obj;

@@ -411,10 +407,10 @@ const expected = type;

if (!pass) {
const message = richText()
.write(mh("notToBeInstanceOf"))
.write("Expected value not to be an instance of:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
const message = errMsg()
.matcherHint("notToBeInstanceOf")
.info("Expected value not to be an instance of:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToBeInstanceOf);
throw new AssertionError(message.compose(), this.notToBeInstanceOf);
}

@@ -425,104 +421,2 @@ return this;

export class ArrayAssertion<T> extends Assertion<T[]> {
toHaveLength(length: number): ArrayAssertion<T> {
const received = this.obj;
const expected = length;
const pass = received.length === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveLength"))
.write("Expected array to have a length ", e(expected),
", instead it have a length ", r(received.length), "\n");
throw new AssertionError(message.compose(), received, true, this.toHaveLength);
}
return this;
}
notToHaveLength(length: number): ArrayAssertion<T> {
const received = this.obj;
const expected = length;
const pass = received.length !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveLength"))
.write("Expected array not to have a length ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToHaveLength);
}
return this;
}
toContain(value: T | Matcher): ArrayAssertion<T> {
const received = this.obj;
const expected = value;
const pass = expected instanceof Matcher ?
received.some((i) => expected.match(i)) :
received.indexOf(expected) !== -1;
if (!pass) {
const message = richText()
.write(mh("toContain"))
.write("Expected array to include:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toContain);
}
return this;
}
notToContain(value: T | Matcher): ArrayAssertion<T> {
const received = this.obj;
const expected = value;
const pass = expected instanceof Matcher ?
!received.some((i) => expected.match(i)) :
received.indexOf(expected) === -1;
if (!pass) {
const message = richText()
.write(mh("notToContain"))
.write("Expected array not to contain:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.notToContain);
}
return this;
}
toMatch(match: T[]): ArrayAssertion<T> {
const received = this.obj;
const expected = match;
const pass = matchArray(received, expected);
if (!pass) {
const message = richText()
.write(mh("toMatch"))
.write("Expected array to match:\n")
.write(" ", e(expected), "\n")
.write("Received:\n")
.write(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
}
return this;
}
notToMatch(match: T[]): ArrayAssertion<T> {
const received = this.obj;
const expected = match;
const pass = !matchArray(received, expected);
if (!pass) {
const message = richText()
.write(mh("notToMatch"))
.write("Expected array not to match:\n")
.write(" ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
}
return this;
}
}
export class NullAssertion extends Assertion<null> {

@@ -542,17 +436,30 @@ constructor() {

export class DateAssertion extends Assertion<Date> { }
export class ErrorAssertion<E extends Error> extends Assertion<E> { }
function matchException(a: any, b: string | Error | ErrorConstructor): boolean {
if (typeof b === "string") {
if (typeof a === "string" && a.indexOf(b) !== -1) {
return true;
} else if (a instanceof Error && a.message.indexOf(b) !== -1) {
return true;
}
} else {
if (b instanceof Error) {
return a.constructor === b.constructor || a instanceof b.constructor;
} else if (b.prototype instanceof Error || b === Error) {
return a.constructor === b || a instanceof b;
}
}
return false;
}
export class FunctionAssertion extends Assertion<Function> {
toHaveArgumentsLength(length: number): FunctionAssertion {
const received = this.obj;
toHaveArgumentsLength(length: number): this {
const received = this.obj.length;
const expected = length;
const pass = received.length === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveArgumentsLength"))
.write("Expected function to have arguments length ", e(expected),
", instead it have arguments length ", r(received.length), "\n");
const message = errMsg()
.matcherHint("toHaveArgumentsLength")
.info(rt`Expected function to have arguments length ${e(expected)}, instead it have length ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHaveArgumentsLength);
throw new AssertionError(message.compose(), this.toHaveArgumentsLength);
}

@@ -562,3 +469,3 @@ return this;

notToHaveArgumentsLength(length: number): FunctionAssertion {
notToHaveArgumentsLength(length: number): this {
const received = this.obj;

@@ -568,7 +475,7 @@ const expected = length;

if (!pass) {
const message = richText()
.write(mh("notToHaveLength"))
.write("Expected function not to have arguments length ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHaveLength")
.info(rt`Expected function not to have arguments length ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHaveArgumentsLength);
throw new AssertionError(message.compose(), this.notToHaveArgumentsLength);
}

@@ -578,12 +485,8 @@ return this;

toThrow<E extends Error | ErrorConstructor>(expected?: E): FunctionAssertion {
const received = this.obj;
toThrow<E extends Error | ErrorConstructor>(expected?: string | E): this {
let pass = false;
let throwed;
try {
this.obj();
} catch (e) {
throwed = e;
if (expected !== undefined && matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = true;

@@ -594,7 +497,7 @@ }

if (!pass) {
const message = richText()
.write(mh("toThrow"))
.write("Expected function to throw an exception ", e(expected), "\n");
const message = errMsg()
.matcherHint("toThrow")
.info(rt`Expected function to throw an exception ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.toThrow);
throw new AssertionError(message.compose(), this.toThrow);
}

@@ -605,12 +508,8 @@

notToThrow<E extends Error | ErrorConstructor>(expected?: E): FunctionAssertion {
const received = this.obj;
notToThrow<E extends Error | ErrorConstructor>(expected?: string | E): this {
let pass = true;
let throwed;
try {
this.obj();
} catch (e) {
throwed = e;
if (expected !== undefined && matchException(throwed, expected) === true) {
if (expected !== undefined && matchException(e, expected) === true) {
pass = false;

@@ -621,7 +520,7 @@ }

if (!pass) {
const message = richText()
.write(mh("notToThrow"))
.write("Expected function not to throw an exception ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToThrow")
.info(rt`Expected function not to throw an exception ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToThrow);
throw new AssertionError(message.compose(), this.notToThrow);
}

@@ -638,3 +537,3 @@

export class NumberAssertion extends Assertion<number> {
toBeApproximatelyEqual(number: number, epsilon = Number.EPSILON): NumberAssertion {
toBeApproximatelyEqual(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -647,11 +546,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ",
"(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be approximately equal to ", e(b), ", intstead received ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeApproximatelyEqual", "received", "expected", "epsilon")
.hint(rt`abs(${rA} - ${eB}) <= (abs(${rA}) < abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt`Expected number to be approximately equal to ${e(b)}, intstead received ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeApproximatelyEqual);
throw new AssertionError(message.compose(), this.toBeApproximatelyEqual);
}

@@ -662,3 +558,3 @@

notToBeApproximatelyEqual(number: number, epsilon = Number.EPSILON): NumberAssertion {
notToBeApproximatelyEqual(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -671,11 +567,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeApproximatelyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ",
"(abs(", rA, ") < abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be approximately equal to ", e(b), ", instead received ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeApproximatelyEqual", "received", "expected", "epsilon")
.hint(rt`!(abs(${rA} - ${eB}) <= (abs(${rA}) < abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rt`Expected number not to be approximately equal to ${e(b)}, instead received ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeApproximatelyEqual);
throw new AssertionError(message.compose(), this.notToBeApproximatelyEqual);
}

@@ -686,3 +579,3 @@

toBeEssentiallyEqual(number: number, epsilon = Number.EPSILON): NumberAssertion {
toBeEssentiallyEqual(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -695,11 +588,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("abs(", rA, " - ", eB, ") <= ",
"(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be essentially equal to ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeEssentiallyEqual", "received", "expected", "epsilon")
.hint(rt`abs(${rA} - ${eB}) <= (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt`Expected number to be essentially equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeEssentiallyEqual);
throw new AssertionError(message.compose(), this.toBeEssentiallyEqual);
}

@@ -710,3 +600,3 @@

notToBeEssentiallyEqual(number: number, epsilon = Number.EPSILON): NumberAssertion {
notToBeEssentiallyEqual(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -719,11 +609,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeEssentiallyEqual", "received", "expected", "epsilon"))
.begin("hint")
.write("!(abs(", rA, " - ", eB, ") <= ",
"(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be essentially equal to ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeEssentiallyEqual", "received", "expected", "epsilon")
.hint(rt`!(abs(${rA} - ${eB}) <= (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}) \n\n`)
.info(rt`Expected number not to be essentially equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeEssentiallyEqual);
throw new AssertionError(message.compose(), this.notToBeEssentiallyEqual);
}

@@ -734,3 +621,3 @@

toBeDefinetelyGreaterThan(number: number, epsilon = Number.EPSILON): NumberAssertion {
toBeDefinetelyGreaterThan(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -743,11 +630,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", rA, " - ", eB, ") > ",
"(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely greater than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint(rt`(${rA} - ${eB}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt`Expected number to be definetely greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeDefinetelyGreaterThan);
throw new AssertionError(message.compose(), this.toBeDefinetelyGreaterThan);
}

@@ -758,3 +642,3 @@

notToBeDefinetelyGreaterThan(number: number, epsilon = Number.EPSILON): NumberAssertion {
notToBeDefinetelyGreaterThan(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -767,11 +651,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", rA, " - ", eB, ") > ",
"(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely greater than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeDefinitelyGreaterThan", "received", "expected", "epsilon")
.hint(rt`!((${rA} - ${eB}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rt`Expected number not to be definetely greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeDefinetelyGreaterThan);
throw new AssertionError(message.compose(), this.notToBeDefinetelyGreaterThan);
}

@@ -782,3 +663,3 @@

toBeDefinetelyLessThan(number: number, epsilon = Number.EPSILON): NumberAssertion {
toBeDefinetelyLessThan(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -791,11 +672,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("(", eB, " - ", rA, ") > ",
"(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, "\n\n")
.end("hint")
.write("Expected number to be definetely less than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint(rt`(${eB} - ${rA}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE}\n\n`)
.info(rt`Expected number to be definetely less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeDefinetelyLessThan);
throw new AssertionError(message.compose(), this.toBeDefinetelyLessThan);
}

@@ -806,3 +684,3 @@

notToBeDefinetelyLessThan(number: number, epsilon = Number.EPSILON): NumberAssertion {
notToBeDefinetelyLessThan(number: number, epsilon = Number.EPSILON): this {
const a = this.obj;

@@ -815,11 +693,8 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeDefinitelyLessThan", "received", "expected", "epsilon"))
.begin("hint")
.write("!((", eB, " - ", rA, ") > ",
"(abs(", rA, ") > abs(", eB, ") ? abs(", eB, ") : abs(", rA, ")) * ", eE, ")\n\n")
.end("hint")
.write("Expected number not to be definetely less than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeDefinitelyLessThan", "received", "expected", "epsilon")
.hint(rt`!((${eB} - ${rA}) > (abs(${rA}) > abs(${eB}) ? abs(${eB}) : abs(${rA})) * ${eE})\n\n`)
.info(rt`Expected number not to be definetely less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeDefinetelyLessThan);
throw new AssertionError(message.compose(), this.notToBeDefinetelyLessThan);
}

@@ -830,3 +705,3 @@

toBeGreaterThan(number: number): NumberAssertion {
toBeGreaterThan(number: number): this {
const a = this.obj;

@@ -837,7 +712,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeGreaterThan"))
.write("Expected number to be greater than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeGreaterThan")
.info(rt`Expected number to be greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeGreaterThan);
throw new AssertionError(message.compose(), this.toBeGreaterThan);
}

@@ -848,3 +723,3 @@

notToBeGreaterThan(number: number): NumberAssertion {
notToBeGreaterThan(number: number): this {
const a = this.obj;

@@ -855,7 +730,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeGreaterThan"))
.write("Expected number not to be greater than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeGreaterThan")
.info(rt`Expected number not to be greater than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeGreaterThan);
throw new AssertionError(message.compose(), this.notToBeGreaterThan);
}

@@ -866,3 +741,3 @@

toBeGreaterThanOrEqual(number: number): NumberAssertion {
toBeGreaterThanOrEqual(number: number): this {
const a = this.obj;

@@ -873,7 +748,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeGreaterThanOrEqual"))
.write("Expected number to be greater than or equal to ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeGreaterThanOrEqual")
.info(rt`Expected number to be greater than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeGreaterThanOrEqual);
throw new AssertionError(message.compose(), this.toBeGreaterThanOrEqual);
}

@@ -884,3 +759,3 @@

notToBeGreaterThanOrEqual(number: number): NumberAssertion {
notToBeGreaterThanOrEqual(number: number): this {
const a = this.obj;

@@ -891,7 +766,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeGreaterThanOrEqual"))
.write("Expected number not to be greater than or equal to ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeGreaterThanOrEqual")
.info(rt`Expected number not to be greater than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeGreaterThanOrEqual);
throw new AssertionError(message.compose(), this.notToBeGreaterThanOrEqual);
}

@@ -902,3 +777,3 @@

toBeLessThan(number: number): NumberAssertion {
toBeLessThan(number: number): this {
const a = this.obj;

@@ -909,7 +784,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeLessThan"))
.write("Expected number to be less than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeLessThan")
.info(rt`Expected number to be less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeLessThan);
throw new AssertionError(message.compose(), this.toBeLessThan);
}

@@ -920,3 +795,3 @@

notToBeLessThan(number: number): NumberAssertion {
notToBeLessThan(number: number): this {
const a = this.obj;

@@ -927,7 +802,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeLessThan"))
.write("Expected number not to be less than ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeLessThan")
.info(rt`Expected number not to be less than ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeLessThan);
throw new AssertionError(message.compose(), this.notToBeLessThan);
}

@@ -938,3 +813,3 @@

toBeLessThanOrEqual(number: number): NumberAssertion {
toBeLessThanOrEqual(number: number): this {
const a = this.obj;

@@ -945,7 +820,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("toBeLessThanOrEqual"))
.write("Expected number to be less than or equal to ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeLessThanOrEqual")
.info(rt`Expected number to be less than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.toBeLessThanOrEqual);
throw new AssertionError(message.compose(), this.toBeLessThanOrEqual);
}

@@ -956,3 +831,3 @@

notToBeLessThanOrEqual(number: number): NumberAssertion {
notToBeLessThanOrEqual(number: number): this {
const a = this.obj;

@@ -963,7 +838,7 @@ const b = number;

if (!pass) {
const message = richText()
.write(mh("notToBeLessThanOrEqual"))
.write("Expected number not to be less than or equal to ", e(b), ", instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("notToBeLessThanOrEqual")
.info(rt`Expected number not to be less than or equal to ${e(b)}, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, b, this.notToBeLessThanOrEqual);
throw new AssertionError(message.compose(), this.notToBeLessThanOrEqual);
}

@@ -974,3 +849,3 @@

toBeNaN(): NumberAssertion {
toBeNaN(): this {
const a = this.obj;

@@ -980,7 +855,7 @@ const pass = Number.isNaN(a);

if (!pass) {
const message = richText()
.write(mh("toBeNaN", "received", ""))
.write("Expected number to be NaN, instead received: ", r(a), "\n");
const message = errMsg()
.matcherHint("toBeNaN", "received", "")
.info(rt`Expected number to be NaN, instead received: ${r(a)}\n`);
throw new AssertionError(message.compose(), a, NaN, this.toBeNaN);
throw new AssertionError(message.compose(), this.toBeNaN);
}

@@ -991,3 +866,3 @@

notToBeNaN(): NumberAssertion {
notToBeNaN(): this {
const a = this.obj;

@@ -997,7 +872,7 @@ const pass = !Number.isNaN(a);

if (!pass) {
const message = richText()
.write(mh("notToBeNaN", "received", ""))
.write("Expected number not to be NaN\n");
const message = errMsg()
.matcherHint("notToBeNaN", "received", "")
.info("Expected number not to be NaN\n");
throw new AssertionError(message.compose(), a, NaN, this.notToBeNaN);
throw new AssertionError(message.compose(), this.notToBeNaN);
}

@@ -1010,13 +885,16 @@

export class StringAssertion extends Assertion<string> {
toHaveLength(length: number): StringAssertion {
const received = this.obj;
toSnapshot() {
return this.obj;
}
toHaveLength(length: number): this {
const received = this.obj.length;
const expected = length;
const pass = received.length === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveLength"))
.write("Expected string to have length ", e(expected),
", instead it have length ", r(received.length), "\n");
const message = errMsg()
.matcherHint("toHaveLength")
.info(rt`Expected string to have length ${e(expected)}, instead it have length ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHaveLength);
throw new AssertionError(message.compose(), this.toHaveLength);
}

@@ -1026,12 +904,12 @@ return this;

notToHaveLength(length: number): StringAssertion {
const received = this.obj;
notToHaveLength(length: number): this {
const received = this.obj.length;
const expected = length;
const pass = received.length !== expected;
const pass = received !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveLength"))
.write("Expected string not to have length ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHaveLength")
.info(rt`Expected string not to have length ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHaveLength);
throw new AssertionError(message.compose(), this.notToHaveLength);
}

@@ -1041,3 +919,3 @@ return this;

toInclude(text: string): StringAssertion {
toInclude(text: string): this {
const received = this.obj;

@@ -1047,8 +925,8 @@ const expected = text;

if (!pass) {
const message = richText()
.write(mh("toInclude"))
.write("Expected string to include ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("toInclude")
.info(rt`Expected string to include ${e(expected)}\n`)
.info(rt`Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toInclude);
throw new AssertionError(message.compose(), this.toInclude);
}

@@ -1058,3 +936,3 @@ return this;

notToInclude(text: string): StringAssertion {
notToInclude(text: string): this {
const received = this.obj;

@@ -1064,8 +942,8 @@ const expected = text;

if (!pass) {
const message = richText()
.write(mh("notToInclude"))
.write("Expected string not to include ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("notToInclude")
.info(rt`Expected string not to include ${e(expected)}\n`)
.info(rt`Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToInclude);
throw new AssertionError(message.compose(), this.notToInclude);
}

@@ -1075,3 +953,3 @@ return this;

toMatch(text: string | RegExp): StringAssertion {
toMatch(text: string | RegExp): this {
const received = this.obj;

@@ -1081,8 +959,8 @@ const expected = text;

if (!pass) {
const message = richText()
.write(mh("toMatch"))
.write("Expected string to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("toMatch")
.info(rt`Expected string to match ${e(expected)}\n`)
.info(rt`Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toMatch);
throw new AssertionError(message.compose(), this.toMatch);
}

@@ -1092,3 +970,3 @@ return this;

notToMatch(text: string | RegExp): StringAssertion {
notToMatch(text: string | RegExp): this {
const received = this.obj;

@@ -1098,8 +976,8 @@ const expected = text;

if (!pass) {
const message = richText()
.write(mh("notToMatch"))
.write("Expected string not to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("notToMatch")
.info(rt`Expected string not to match ${e(expected)}\n`)
.info(rt`Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToMatch);
throw new AssertionError(message.compose(), this.notToMatch);
}

@@ -1113,13 +991,25 @@ return this;

export class ObjectAssertion<T extends object> extends Assertion<T> {
toMatch(matcher: Matcher): ObjectAssertion<T> {
readonly type: string;
constructor(obj: T, type = "object") {
super(obj);
this.type = type;
}
toSnapshot() {
return toSnapshot(this.obj);
}
toBeEqual(expected: T): this {
const received = this.obj;
const expected = matcher;
const pass = matcher.match(received);
const pass = isEqual(received, expected);
if (!pass) {
const message = richText()
.write(mh("toMatch"))
.write("Expected Object to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("toBeEqual")
.info(`Expected ${this.type} to be equal (_.isEqual()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), received, true, this.toMatch);
throw new AssertionError(message.compose(), this.toBeEqual);
}

@@ -1129,32 +1019,204 @@ return this;

notToMatch(matcher: Matcher): ObjectAssertion<T> {
notToBeEqual(expected: T): this {
const received = this.obj;
const expected = matcher;
const pass = !matcher.match(received);
const pass = !isEqual(received, expected);
if (!pass) {
const message = richText()
.write(mh("notToMatch"))
.write("Expected Object not to match ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("notToMatch")
.info(`Expected ${this.type} not to be equal (!_.isEqual()):\n`)
.info(" ", e(expected), "\n");
throw new AssertionError(message.compose(), received, true, this.notToMatch);
throw new AssertionError(message.compose(), this.notToBeEqual);
}
return this;
}
toBeEqualWith(expected: T, customizer: isMatchCustomizer): this {
const received = this.obj;
const pass = isEqualWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("toBeEqualWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to be equal with (_.isEqualWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toBeEqualWith);
}
return this;
}
notToBeEqualWith(expected: T, customizer: isMatchCustomizer): this {
const received = this.obj;
const pass = !isEqualWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("notToBeEqualWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to be equal with (!_.isEqualWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToBeEqualWith);
}
return this;
}
toMatch(expected: any): this {
const received = this.obj;
const pass = isMatch(received, expected);
if (!pass) {
const message = errMsg()
.matcherHint("toMatch")
.info(`Expected ${this.type} to match (_.isMatch()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toMatch);
}
return this;
}
notToMatch(expected: any): this {
const received = this.obj;
const pass = !isMatch(received, expected);
if (!pass) {
const message = errMsg()
.matcherHint("notToMatch")
.info(`Expected ${this.type} not to match (!_.isMatch()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToMatch);
}
return this;
}
toMatchWith(expected: any, customizer: isMatchCustomizer): this {
const received = this.obj;
const pass = isMatchWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("toMatchWith", "received", "expected", "customizer")
.info(`Expected ${this.type} to match with customizer (_.isMatchWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toMatchWith);
}
return this;
}
notToMatchWith(expected: any, customizer: isMatchCustomizer): this {
const received = this.obj;
const pass = !isMatchWith(received, expected, customizer);
if (!pass) {
const message = errMsg()
.matcherHint("notToMatchWith", "received", "expected", "customizer")
.info(`Expected ${this.type} not to match with customizer (!_.isMatchWith()):\n`)
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToMatchWith);
}
return this;
}
}
export const enum RegExpFlags {
Global = 1,
IgnoreCase = 1 << 1,
Multiline = 1 << 2,
Unicode = 1 << 3,
Sticky = 1 << 4,
export class ArrayAssertion<T> extends ObjectAssertion<T[]> {
constructor(obj: T[]) {
super(obj, "array");
}
toHaveLength(length: number): this {
const received = this.obj;
const expected = length;
const pass = received.length === expected;
if (!pass) {
const message = errMsg()
.matcherHint("toHaveLength")
.info(rt`Expected array to have a length ${e(expected)} instead it have a length ${r(received.length)}\n`);
throw new AssertionError(message.compose(), this.toHaveLength);
}
return this;
}
notToHaveLength(length: number): this {
const received = this.obj;
const expected = length;
const pass = received.length !== expected;
if (!pass) {
const message = errMsg()
.matcherHint("notToHaveLength")
.info(rt`Expected array not to have a length ${e(expected)}\n`);
throw new AssertionError(message.compose(), this.notToHaveLength);
}
return this;
}
toContain(value: T): this {
const received = this.obj;
const expected = value;
const pass = received.indexOf(expected) !== -1;
if (!pass) {
const message = errMsg()
.matcherHint("toContain")
.info("Expected array to contain:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.toContain);
}
return this;
}
notToContain(value: T): this {
const received = this.obj;
const expected = value;
const pass = received.indexOf(expected) === -1;
if (!pass) {
const message = errMsg()
.matcherHint("notToContain")
.info("Expected array not to contain:\n")
.info(" ", e(expected), "\n")
.info("Received:\n")
.info(" ", r(received), "\n");
throw new AssertionError(message.compose(), this.notToContain);
}
return this;
}
}
export class RegExpAssertion extends Assertion<RegExp> {
toSnapshot() {
return this.obj.valueOf();
export class DateAssertion extends ObjectAssertion<Date> {
constructor(obj: Date) {
super(obj, "Date");
}
}
toTest(text: string): RegExpAssertion {
export class ErrorAssertion<E extends Error> extends ObjectAssertion<E> {
constructor(obj: E) {
super(obj, "Error");
}
}
export class RegExpAssertion extends ObjectAssertion<RegExp> {
constructor(obj: RegExp) {
super(obj, "RegExp");
}
toSnapshot(): string {
return this.obj.valueOf().toString();
}
toTest(text: string): this {
const received = this.obj;

@@ -1164,8 +1226,8 @@ const expected = text;

if (!pass) {
const message = richText()
.write(mh("toTest"))
.write("Expected RegExp to test ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("toTest")
.info(rt`Expected RegExp to test ${e(expected)}\n`)
.info(rt`Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toTest);
throw new AssertionError(message.compose(), this.toTest);
}

@@ -1175,3 +1237,3 @@ return this;

notToTest(text: string): RegExpAssertion {
notToTest(text: string): this {
const received = this.obj;

@@ -1181,8 +1243,8 @@ const expected = text;

if (!pass) {
const message = richText()
.write(mh("notToTest"))
.write("Expected RegExp not to test ", e(expected), "\n")
.write("Received: ", r(received), "\n");
const message = errMsg()
.matcherHint("notToTest")
.info(rt`Expected RegExp not to test ${e(expected)}\n`)
.info(rt`Received: ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToTest);
throw new AssertionError(message.compose(), this.notToTest);
}

@@ -1193,13 +1255,17 @@ return this;

export class MapAssertion<K, V> extends Assertion<Map<K, V>> {
toHaveSize(size: number): MapAssertion<K, V> {
const received = this.obj;
export class MapAssertion<K, V> extends ObjectAssertion<Map<K, V>> {
constructor(obj: Map<K, V>) {
super(obj, "Map");
}
toHaveSize(size: number): this {
const received = this.obj.size;
const expected = size;
const pass = received.size === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveSize"))
.write("Expected Map to have size ", e(expected), ", instead it have size ", r(received.size), "\n");
const message = errMsg()
.matcherHint("toHaveSize")
.info(rt`Expected Map to have size ${e(expected)}, instead it have size ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHaveSize);
throw new AssertionError(message.compose(), this.toHaveSize);
}

@@ -1210,12 +1276,12 @@

notToHaveSize(size: number): MapAssertion<K, V> {
const received = this.obj;
notToHaveSize(size: number): this {
const received = this.obj.size;
const expected = size;
const pass = received.size !== expected;
const pass = received !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveSize"))
.write("Expected Map not to have size ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHaveSize")
.info(rt`Expected Map not to have size ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHaveSize);
throw new AssertionError(message.compose(), this.notToHaveSize);
}

@@ -1226,3 +1292,3 @@

toHave(key: K): MapAssertion<K, V> {
toHave(key: K): this {
const received = this.obj;

@@ -1232,7 +1298,7 @@ const expected = key;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected Map to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("toHave")
.info(rt`Expected Map to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHave);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1242,3 +1308,3 @@ return this;

notToHave(key: K): MapAssertion<K, V> {
notToHave(key: K): this {
const received = this.obj;

@@ -1248,7 +1314,7 @@ const expected = key;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected Map not to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHave")
.info(rt`Expected Map not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHave);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1259,13 +1325,17 @@ return this;

export class SetAssertion<V> extends Assertion<Set<V>> {
toHaveSize(size: number): SetAssertion<V> {
const received = this.obj;
export class SetAssertion<V> extends ObjectAssertion<Set<V>> {
constructor(obj: Set<V>) {
super(obj, "Set");
}
toHaveSize(size: number): this {
const received = this.obj.size;
const expected = size;
const pass = received.size === expected;
const pass = received === expected;
if (!pass) {
const message = richText()
.write(mh("toHaveSize"))
.write("Expected Set to have size ", e(expected), ", instead it have size ", r(received.size), "\n");
const message = errMsg()
.matcherHint("toHaveSize")
.info(rt`Expected Set to have size ${e(expected)}, instead it have size ${r(received)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHaveSize);
throw new AssertionError(message.compose(), this.toHaveSize);
}

@@ -1276,12 +1346,12 @@

notToHaveSize(size: number): SetAssertion<V> {
const received = this.obj;
notToHaveSize(size: number): this {
const received = this.obj.size;
const expected = size;
const pass = received.size !== expected;
const pass = received !== expected;
if (!pass) {
const message = richText()
.write(mh("notToHaveSize"))
.write("Expected Set not to have size ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHaveSize")
.info(rt`Expected Set not to have size ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHaveSize);
throw new AssertionError(message.compose(), this.notToHaveSize);
}

@@ -1292,3 +1362,3 @@

toHave(value: V): SetAssertion<V> {
toHave(value: V): this {
const received = this.obj;

@@ -1298,7 +1368,7 @@ const expected = value;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected Set to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("toHave")
.info(rt`Expected Set to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHave);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1308,3 +1378,3 @@ return this;

notToHave(value: V): SetAssertion<V> {
notToHave(value: V): this {
const received = this.obj;

@@ -1314,7 +1384,7 @@ const expected = value;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected Set not to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHave")
.info(rt`Expected Set not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHave);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1325,4 +1395,8 @@ return this;

export class WeakMapAssertion<K extends object, V> extends Assertion<WeakMap<K, V>> {
toHave(key: K): WeakMapAssertion<K, V> {
export class WeakMapAssertion<K extends object, V> extends ObjectAssertion<WeakMap<K, V>> {
constructor(obj: WeakMap<K, V>) {
super(obj, "WeakMap");
}
toHave(key: K): this {
const received = this.obj;

@@ -1332,7 +1406,7 @@ const expected = key;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected WeakMap to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("toHave")
.info(rt`Expected WeakMap to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHave);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1342,3 +1416,3 @@ return this;

notToHave(key: K): WeakMapAssertion<K, V> {
notToHave(key: K): this {
const received = this.obj;

@@ -1348,7 +1422,7 @@ const expected = key;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected WeakMap not to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHave")
.info(rt`Expected WeakMap not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHave);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1359,4 +1433,8 @@ return this;

export class WeakSetAssertion<V> extends Assertion<WeakSet<V>> {
toHave(value: V): WeakSetAssertion<V> {
export class WeakSetAssertion<V> extends ObjectAssertion<WeakSet<V>> {
constructor(obj: WeakSet<V>) {
super(obj, "WeakSet");
}
toHave(value: V): this {
const received = this.obj;

@@ -1366,7 +1444,7 @@ const expected = value;

if (!pass) {
const message = richText()
.write(mh("toHave"))
.write("Expected WeakSet to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("toHave")
.info(rt`Expected WeakSet to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.toHave);
throw new AssertionError(message.compose(), this.toHave);
}

@@ -1376,3 +1454,3 @@ return this;

notToHave(value: V): WeakSetAssertion<V> {
notToHave(value: V): this {
const received = this.obj;

@@ -1382,7 +1460,7 @@ const expected = value;

if (!pass) {
const message = richText()
.write(mh("notToHave"))
.write("Expected WeakSet not to have ", e(expected), "\n");
const message = errMsg()
.matcherHint("notToHave")
.info(rt`Expected WeakSet not to have ${e(expected)}\n`);
throw new AssertionError(message.compose(), received, true, this.notToHave);
throw new AssertionError(message.compose(), this.notToHave);
}

@@ -1389,0 +1467,0 @@ return this;

import * as prettyFormat from "pretty-format";
import { RichText } from "rtext";
import { RichTextWriter } from "rtext-writer";
import { RichTextWriter, annotate } from "rtext-writer";

@@ -34,136 +34,111 @@ const PLUGINS = [

const NUMBERS = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
];
export function leftPad(p: string, s: string): string {
return s.replace(/^/gm, p);
}
export function pluralize(word: string, count: number): string {
const result = ((count < NUMBERS.length) ? NUMBERS[count] : count.toString()) + " " + word;
if (count === 1) {
return result;
}
return result + "s";
/**
* hl is a function that highlights matched text regions. By default it highlights trailing whitespaces.
*
* @param text Raw text.
* @param regexp RegExp matcher.
* @param type Annotation type.
* @returns Rich Text.
*/
export function hl(
text: string,
regexp = /\s+$/gm,
type = "highlight",
): RichText {
return annotate(text, regexp, type);
}
export function matcherHint(
writer: RichTextWriter,
matcherName: string,
received: string = "received",
expected: string = "expected",
secondArgument?: string,
): void {
writer
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(`).${matcherName}(`)
.begin("expected").write(expected).end("expected");
if (secondArgument !== undefined) {
export function r(value: any, raw?: boolean): (writer: RichTextWriter) => void {
return function (writer: RichTextWriter): void {
writer
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
writer
.write(")")
.write("\n\n")
.end("matcherHint");
.begin("received")
.write(raw ? value : hl(stringify(value)))
.end("received");
};
}
export function highlightTrailingWhitespace(
text: string,
): RichText {
const re = /\s+$/gm;
let match = re.exec(text);
const annotations = [];
while (match !== null) {
const start = match.index;
const end = start + match[0].length;
annotations.push({
type: "trailingWhitespace",
start: start,
end: end,
data: undefined,
key: undefined,
});
match = re.exec(text);
}
return {
text: text,
annotations: annotations.length === 0 ? undefined : annotations,
export function e(value: any, raw?: boolean): (writer: RichTextWriter) => void {
return function (writer: RichTextWriter): void {
writer
.begin("expected")
.write(raw ? value : hl(stringify(value)))
.end("expected");
};
}
export function printReceived(
writer: RichTextWriter,
value: any,
raw?: boolean,
) {
writer
.begin("received")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("received");
}
export class ErrorMessageWriter extends RichTextWriter {
matcherHint(
matcherName: string,
received: string = "received",
expected: string = "expected",
secondArgument?: string,
): this {
this
.begin("matcherHint")
.write("expect(")
.begin("received").write(received).end("received")
.write(`).${matcherName}(`)
.begin("expected").write(expected).end("expected");
export function printExpected(
writer: RichTextWriter,
value: any,
raw?: boolean,
) {
writer
.begin("expected")
.write(raw ? value : highlightTrailingWhitespace(stringify(value)))
.end("expected");
}
if (secondArgument !== undefined) {
this
.write(", ")
.begin("expected").write(secondArgument).end("expected");
}
export function printInfo(
writer: RichTextWriter,
s: string,
) {
writer
.begin("info")
.write(s)
.end("info");
}
this
.write(")")
.write("\n\n")
.end("matcherHint");
export function mh(
matcherName: string,
received: string = "received",
expected: string = "expected",
secondArgument?: string,
): (w: RichTextWriter) => void {
return function (w: RichTextWriter): void {
matcherHint(w, matcherName, received, expected, secondArgument);
};
}
return this;
}
export function r(value: any, raw?: boolean): (w: RichTextWriter) => void {
return function (w: RichTextWriter): void {
printReceived(w, value, raw);
};
}
hint(...ws: Array<string | RichText | ((w: RichTextWriter) => void)>): this {
this
.continue("hint")
.write(...ws)
.end("hint");
return this;
}
export function e(value: any, raw?: boolean): (w: RichTextWriter) => void {
return function (w: RichTextWriter): void {
printExpected(w, value, raw);
};
info(...ws: Array<string | RichText | ((w: RichTextWriter) => void)>): this {
this
.continue("info")
.write(...ws)
.end("info");
return this;
}
diff(...ws: Array<string | RichText | ((w: RichTextWriter) => void)>): this {
this
.begin("diff")
.write(...ws)
.end("diff");
return this;
}
received(value: any): this {
this
.begin("received")
.write(hl(stringify(value)))
.end("received");
return this;
}
expected(value: any): this {
this
.begin("expected")
.write(hl(stringify(value)))
.end("expected");
return this;
}
}
export function info(s: string): (w: RichTextWriter) => void {
return function (w: RichTextWriter): void {
printInfo(w, s);
};
export function errMsg(): ErrorMessageWriter {
return new ErrorMessageWriter();
}

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc