summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-03-26 13:15:16 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-26 08:15:16 -0400
commit630d0f213d54fe2dcce94b338a87373d64e3f716 (patch)
tree00375af0ff6d8496fbcc635dfe9146356a27b27e /testing
parent4347148d507868d508782f154f2b49dbe6ea359b (diff)
Fix assertEquals for RegExp & Date (denoland/deno_std#305)
Original: https://github.com/denoland/deno_std/commit/e17364b91fb5360624e9529ed26cb3c6f0ca6a38
Diffstat (limited to 'testing')
-rw-r--r--testing/asserts.ts10
-rw-r--r--testing/asserts_test.ts4
2 files changed, 14 insertions, 0 deletions
diff --git a/testing/asserts.ts b/testing/asserts.ts
index 6d975bbb5..eb5e11969 100644
--- a/testing/asserts.ts
+++ b/testing/asserts.ts
@@ -16,6 +16,16 @@ export class AssertionError extends Error {
export function equal(c: unknown, d: unknown): boolean {
const seen = new Map();
return (function compare(a: unknown, b: unknown) {
+ // Have to render RegExp & Date for string comparison
+ // unless it's mistreated as object
+ if (
+ a &&
+ b &&
+ ((a instanceof RegExp && b instanceof RegExp) ||
+ (a instanceof Date && b instanceof Date))
+ ) {
+ return String(a) === String(b);
+ }
if (Object.is(a, b)) {
return true;
}
diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts
index 6f82d4169..87e0335ac 100644
--- a/testing/asserts_test.ts
+++ b/testing/asserts_test.ts
@@ -36,6 +36,10 @@ test(function testingEqual() {
{ hello: "world", hi: { there: "everyone else" } }
)
);
+ assert(equal(/deno/, /deno/));
+ assert(!equal(/deno/, /node/));
+ assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3)));
+ assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3)));
});
test(function testingNotEquals() {