diff options
Diffstat (limited to 'std/testing')
-rw-r--r-- | std/testing/asserts.ts | 4 | ||||
-rw-r--r-- | std/testing/asserts_test.ts | 31 |
2 files changed, 34 insertions, 1 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index 0cbd6d2ad..10e2b9c97 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -82,11 +82,13 @@ export function equal(c: unknown, d: unknown): boolean { a && b && ((a instanceof RegExp && b instanceof RegExp) || - (a instanceof Date && b instanceof Date) || (a instanceof URL && b instanceof URL)) ) { return String(a) === String(b); } + if (a instanceof Date && b instanceof Date) { + return a.getTime() === b.getTime(); + } if (Object.is(a, b)) { return true; } diff --git a/std/testing/asserts_test.ts b/std/testing/asserts_test.ts index 854cb9730..011e98590 100644 --- a/std/testing/asserts_test.ts +++ b/std/testing/asserts_test.ts @@ -41,6 +41,12 @@ Deno.test("testingEqual", function (): void { 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))); + assert( + !equal( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20) + ) + ); assert(equal(new Set([1]), new Set([1]))); assert(!equal(new Set([1]), new Set([2]))); assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1]))); @@ -128,6 +134,10 @@ Deno.test("testingNotEquals", function (): void { const b = { bar: "foo" }; assertNotEquals(a, b); assertNotEquals("Denosaurus", "Tyrannosaurus"); + assertNotEquals( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20) + ); let didThrow; try { assertNotEquals("Raptor", "Raptor"); @@ -365,6 +375,27 @@ Deno.test({ }); Deno.test({ + name: "failed with date", + fn(): void { + assertThrows( + (): void => + assertEquals( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20) + ), + AssertionError, + [ + "Values are not equal:", + ...createHeader(), + removed(`- ${new Date(2019, 0, 3, 4, 20, 1, 10).toISOString()}`), + added(`+ ${new Date(2019, 0, 3, 4, 20, 1, 20).toISOString()}`), + "", + ].join("\n") + ); + }, +}); + +Deno.test({ name: "strict pass case", fn(): void { assertStrictEquals(true, true); |