summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
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() {