2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-03-07 09:08:19 -05:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertNotEquals,
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStringContains,
|
2019-03-07 09:08:19 -05:00
|
|
|
assertArrayContains,
|
|
|
|
assertMatch,
|
2019-03-08 02:32:46 -05:00
|
|
|
assertEquals,
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStrictEquals,
|
2019-03-08 16:04:43 -05:00
|
|
|
assertThrows,
|
2020-06-04 10:43:05 -04:00
|
|
|
assertThrowsAsync,
|
2019-03-08 16:04:43 -05:00
|
|
|
AssertionError,
|
|
|
|
equal,
|
|
|
|
fail,
|
2019-03-08 02:32:46 -05:00
|
|
|
unimplemented,
|
2020-03-28 13:03:49 -04:00
|
|
|
unreachable,
|
2019-03-07 09:08:19 -05:00
|
|
|
} from "./asserts.ts";
|
2020-05-19 14:19:26 -04:00
|
|
|
import { red, green, gray, bold, yellow } from "../fmt/colors.ts";
|
2019-03-05 14:58:28 -05:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingEqual", function (): void {
|
2019-03-06 16:39:50 -05:00
|
|
|
assert(equal("world", "world"));
|
|
|
|
assert(!equal("hello", "world"));
|
|
|
|
assert(equal(5, 5));
|
|
|
|
assert(!equal(5, 6));
|
|
|
|
assert(equal(NaN, NaN));
|
|
|
|
assert(equal({ hello: "world" }, { hello: "world" }));
|
|
|
|
assert(!equal({ world: "hello" }, { hello: "world" }));
|
|
|
|
assert(
|
|
|
|
equal(
|
|
|
|
{ hello: "world", hi: { there: "everyone" } },
|
|
|
|
{ hello: "world", hi: { there: "everyone" } }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(
|
|
|
|
!equal(
|
|
|
|
{ hello: "world", hi: { there: "everyone" } },
|
|
|
|
{ hello: "world", hi: { there: "everyone else" } }
|
|
|
|
)
|
|
|
|
);
|
2019-03-26 08:15:16 -04:00
|
|
|
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)));
|
2019-04-22 09:39:33 -04:00
|
|
|
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])));
|
2019-11-04 10:21:43 -05:00
|
|
|
assert(equal(new Set([1, new Set([2, 3])]), new Set([new Set([3, 2]), 1])));
|
2019-04-22 09:39:33 -04:00
|
|
|
assert(!equal(new Set([1, 2]), new Set([3, 2, 1])));
|
|
|
|
assert(!equal(new Set([1, 2, 3]), new Set([4, 5, 6])));
|
|
|
|
assert(equal(new Set("denosaurus"), new Set("denosaurussss")));
|
2019-10-29 20:23:54 -04:00
|
|
|
assert(equal(new Map(), new Map()));
|
|
|
|
assert(
|
|
|
|
equal(
|
2019-11-13 13:42:34 -05:00
|
|
|
new Map([
|
|
|
|
["foo", "bar"],
|
2020-03-28 13:03:49 -04:00
|
|
|
["baz", "baz"],
|
2019-11-13 13:42:34 -05:00
|
|
|
]),
|
|
|
|
new Map([
|
|
|
|
["foo", "bar"],
|
2020-03-28 13:03:49 -04:00
|
|
|
["baz", "baz"],
|
2019-11-13 13:42:34 -05:00
|
|
|
])
|
2019-10-29 20:23:54 -04:00
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(
|
|
|
|
equal(
|
|
|
|
new Map([["foo", new Map([["bar", "baz"]])]]),
|
|
|
|
new Map([["foo", new Map([["bar", "baz"]])]])
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(
|
|
|
|
equal(
|
|
|
|
new Map([["foo", { bar: "baz" }]]),
|
|
|
|
new Map([["foo", { bar: "baz" }]])
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(
|
|
|
|
equal(
|
2019-11-13 13:42:34 -05:00
|
|
|
new Map([
|
|
|
|
["foo", "bar"],
|
2020-03-28 13:03:49 -04:00
|
|
|
["baz", "qux"],
|
2019-11-13 13:42:34 -05:00
|
|
|
]),
|
|
|
|
new Map([
|
|
|
|
["baz", "qux"],
|
2020-03-28 13:03:49 -04:00
|
|
|
["foo", "bar"],
|
2019-11-13 13:42:34 -05:00
|
|
|
])
|
2019-10-29 20:23:54 -04:00
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(equal(new Map([["foo", ["bar"]]]), new Map([["foo", ["bar"]]])));
|
|
|
|
assert(!equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]])));
|
|
|
|
assert(
|
2019-11-13 13:42:34 -05:00
|
|
|
!equal(
|
|
|
|
new Map([["foo", "bar"]]),
|
|
|
|
new Map([
|
|
|
|
["foo", "bar"],
|
2020-03-28 13:03:49 -04:00
|
|
|
["bar", "baz"],
|
2019-11-13 13:42:34 -05:00
|
|
|
])
|
|
|
|
)
|
2019-10-29 20:23:54 -04:00
|
|
|
);
|
|
|
|
assert(
|
|
|
|
!equal(
|
|
|
|
new Map([["foo", new Map([["bar", "baz"]])]]),
|
|
|
|
new Map([["foo", new Map([["bar", "qux"]])]])
|
|
|
|
)
|
|
|
|
);
|
2019-11-04 10:21:43 -05:00
|
|
|
assert(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, true]])));
|
|
|
|
assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]])));
|
|
|
|
assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]])));
|
|
|
|
assert(equal([1, 2, 3], [1, 2, 3]));
|
|
|
|
assert(equal([1, [2, 3]], [1, [2, 3]]));
|
|
|
|
assert(!equal([1, 2, 3, 4], [1, 2, 3]));
|
|
|
|
assert(!equal([1, 2, 3, 4], [1, 2, 3]));
|
|
|
|
assert(!equal([1, 2, 3, 4], [1, 4, 2, 3]));
|
|
|
|
assert(equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([1, 2, 3, 4])));
|
|
|
|
assert(!equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3])));
|
2020-06-13 10:01:05 -04:00
|
|
|
assert(
|
|
|
|
equal(new URL("https://example.test"), new URL("https://example.test"))
|
|
|
|
);
|
|
|
|
assert(
|
|
|
|
!equal(
|
|
|
|
new URL("https://example.test"),
|
|
|
|
new URL("https://example.test/with-path")
|
|
|
|
)
|
|
|
|
);
|
2019-03-06 16:39:50 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingNotEquals", function (): void {
|
2019-03-07 09:08:19 -05:00
|
|
|
const a = { foo: "bar" };
|
|
|
|
const b = { bar: "foo" };
|
|
|
|
assertNotEquals(a, b);
|
|
|
|
assertNotEquals("Denosaurus", "Tyrannosaurus");
|
|
|
|
let didThrow;
|
|
|
|
try {
|
|
|
|
assertNotEquals("Raptor", "Raptor");
|
|
|
|
didThrow = false;
|
|
|
|
} catch (e) {
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-07 09:08:19 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assertEquals(didThrow, true);
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertStringContains", function (): void {
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStringContains("Denosaurus", "saur");
|
|
|
|
assertStringContains("Denosaurus", "Deno");
|
|
|
|
assertStringContains("Denosaurus", "rus");
|
2019-03-07 09:08:19 -05:00
|
|
|
let didThrow;
|
|
|
|
try {
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStringContains("Denosaurus", "Raptor");
|
2019-03-07 09:08:19 -05:00
|
|
|
didThrow = false;
|
|
|
|
} catch (e) {
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-07 09:08:19 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assertEquals(didThrow, true);
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingArrayContains", function (): void {
|
2019-03-07 09:08:19 -05:00
|
|
|
const fixture = ["deno", "iz", "luv"];
|
|
|
|
const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
|
|
|
|
assertArrayContains(fixture, ["deno"]);
|
|
|
|
assertArrayContains(fixtureObject, [{ deno: "luv" }]);
|
2020-06-24 08:29:50 -04:00
|
|
|
assertArrayContains(
|
|
|
|
Uint8Array.from([1, 2, 3, 4]),
|
|
|
|
Uint8Array.from([1, 2, 3])
|
|
|
|
);
|
2020-06-02 23:38:46 -04:00
|
|
|
assertThrows(
|
|
|
|
(): void => assertArrayContains(fixtureObject, [{ deno: "node" }]),
|
|
|
|
AssertionError,
|
|
|
|
`actual: "[ { deno: "luv" }, { deno: "Js" } ]" expected to contain: "[ { deno: "node" } ]"\nmissing: [ { deno: "node" } ]`
|
|
|
|
);
|
2019-03-05 14:58:28 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertStringContainsThrow", function (): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStringContains("Denosaurus from Jurassic", "Raptor");
|
2019-03-05 14:58:28 -05:00
|
|
|
} catch (e) {
|
|
|
|
assert(
|
|
|
|
e.message ===
|
2020-05-25 13:32:34 -04:00
|
|
|
`actual: "Denosaurus from Jurassic" expected to contain: "Raptor"`
|
2019-03-05 14:58:28 -05:00
|
|
|
);
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-05 14:58:28 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertStringMatching", function (): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
assertMatch("foobar@deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/));
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertStringMatchingThrows", function (): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/));
|
|
|
|
} catch (e) {
|
|
|
|
assert(
|
|
|
|
e.message ===
|
|
|
|
`actual: "Denosaurus from Jurassic" expected to match: "/Raptor/"`
|
|
|
|
);
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-05 14:58:28 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
2019-03-08 02:32:46 -05:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertsUnimplemented", function (): void {
|
2019-03-08 02:32:46 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
unimplemented();
|
|
|
|
} catch (e) {
|
|
|
|
assert(e.message === "unimplemented");
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-08 02:32:46 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertsUnreachable", function (): void {
|
2019-03-08 02:32:46 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
unreachable();
|
|
|
|
} catch (e) {
|
|
|
|
assert(e.message === "unreachable");
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-08 02:32:46 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
2019-03-08 16:04:43 -05:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertFail", function (): void {
|
2019-03-08 16:04:43 -05:00
|
|
|
assertThrows(fail, AssertionError, "Failed assertion.");
|
|
|
|
assertThrows(
|
2019-04-24 07:41:23 -04:00
|
|
|
(): void => {
|
2019-03-08 16:04:43 -05:00
|
|
|
fail("foo");
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"Failed assertion: foo"
|
|
|
|
);
|
|
|
|
});
|
2019-08-14 10:22:31 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertFailWithWrongErrorClass", function (): void {
|
2020-03-09 17:46:55 -04:00
|
|
|
assertThrows(
|
|
|
|
(): void => {
|
|
|
|
//This next assertThrows will throw an AssertionError due to the wrong
|
|
|
|
//expected error class
|
|
|
|
assertThrows(
|
|
|
|
(): void => {
|
|
|
|
fail("foo");
|
|
|
|
},
|
|
|
|
Error,
|
|
|
|
"Failed assertion: foo"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
`Expected error to be instance of "Error", but was "AssertionError"`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertThrowsWithReturnType", () => {
|
2020-06-04 10:43:05 -04:00
|
|
|
assertThrows(() => {
|
|
|
|
throw new Error();
|
|
|
|
return "a string";
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("testingAssertThrowsAsyncWithReturnType", () => {
|
2020-06-04 10:43:05 -04:00
|
|
|
assertThrowsAsync(() => {
|
|
|
|
throw new Error();
|
|
|
|
return Promise.resolve("a Promise<string>");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-14 10:22:31 -04:00
|
|
|
const createHeader = (): string[] => [
|
|
|
|
"",
|
|
|
|
"",
|
2020-04-10 10:10:45 -04:00
|
|
|
` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${green(
|
|
|
|
bold("Expected")
|
|
|
|
)}`,
|
2019-08-14 10:22:31 -04:00
|
|
|
"",
|
2020-03-28 13:03:49 -04:00
|
|
|
"",
|
2019-08-14 10:22:31 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
const added: (s: string) => string = (s: string): string => green(bold(s));
|
|
|
|
const removed: (s: string) => string = (s: string): string => red(bold(s));
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-08-14 10:22:31 -04:00
|
|
|
name: "pass case",
|
|
|
|
fn(): void {
|
|
|
|
assertEquals({ a: 10 }, { a: 10 });
|
|
|
|
assertEquals(true, true);
|
|
|
|
assertEquals(10, 10);
|
|
|
|
assertEquals("abc", "abc");
|
|
|
|
assertEquals({ a: 10, b: { c: "1" } }, { a: 10, b: { c: "1" } });
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-08-14 10:22:31 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-08-14 10:22:31 -04:00
|
|
|
name: "failed with number",
|
|
|
|
fn(): void {
|
|
|
|
assertThrows(
|
|
|
|
(): void => assertEquals(1, 2),
|
|
|
|
AssertionError,
|
2020-05-15 09:49:11 -04:00
|
|
|
[
|
|
|
|
"Values are not equal:",
|
|
|
|
...createHeader(),
|
2020-05-19 14:19:26 -04:00
|
|
|
removed(`- ${yellow("1")}`),
|
|
|
|
added(`+ ${yellow("2")}`),
|
2020-05-15 09:49:11 -04:00
|
|
|
"",
|
|
|
|
].join("\n")
|
2019-08-14 10:22:31 -04:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-08-14 10:22:31 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-08-14 10:22:31 -04:00
|
|
|
name: "failed with number vs string",
|
|
|
|
fn(): void {
|
|
|
|
assertThrows(
|
|
|
|
(): void => assertEquals(1, "1"),
|
|
|
|
AssertionError,
|
2020-05-15 09:49:11 -04:00
|
|
|
[
|
|
|
|
"Values are not equal:",
|
|
|
|
...createHeader(),
|
2020-05-19 14:19:26 -04:00
|
|
|
removed(`- ${yellow("1")}`),
|
2020-05-15 09:49:11 -04:00
|
|
|
added(`+ "1"`),
|
|
|
|
].join("\n")
|
2019-08-14 10:22:31 -04:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-08-14 10:22:31 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-08-14 10:22:31 -04:00
|
|
|
name: "failed with array",
|
|
|
|
fn(): void {
|
|
|
|
assertThrows(
|
|
|
|
(): void => assertEquals([1, "2", 3], ["1", "2", 3]),
|
|
|
|
AssertionError,
|
|
|
|
[
|
2020-05-15 09:49:11 -04:00
|
|
|
"Values are not equal:",
|
2019-08-14 10:22:31 -04:00
|
|
|
...createHeader(),
|
2020-05-19 14:19:26 -04:00
|
|
|
removed(`- [ ${yellow("1")}, ${green('"2"')}, ${yellow("3")} ]`),
|
|
|
|
added(`+ [ ${green('"1"')}, ${green('"2"')}, ${yellow("3")} ]`),
|
2020-03-28 13:03:49 -04:00
|
|
|
"",
|
2019-08-14 10:22:31 -04:00
|
|
|
].join("\n")
|
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-08-14 10:22:31 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-08-14 10:22:31 -04:00
|
|
|
name: "failed with object",
|
|
|
|
fn(): void {
|
|
|
|
assertThrows(
|
|
|
|
(): void => assertEquals({ a: 1, b: "2", c: 3 }, { a: 1, b: 2, c: [3] }),
|
|
|
|
AssertionError,
|
|
|
|
[
|
2020-05-15 09:49:11 -04:00
|
|
|
"Values are not equal:",
|
2019-08-14 10:22:31 -04:00
|
|
|
...createHeader(),
|
2020-05-19 14:19:26 -04:00
|
|
|
removed(
|
|
|
|
`- { a: ${yellow("1")}, b: ${green('"2"')}, c: ${yellow("3")} }`
|
|
|
|
),
|
|
|
|
added(
|
|
|
|
`+ { a: ${yellow("1")}, b: ${yellow("2")}, c: [ ${yellow("3")} ] }`
|
|
|
|
),
|
2020-03-28 13:03:49 -04:00
|
|
|
"",
|
2019-08-14 10:22:31 -04:00
|
|
|
].join("\n")
|
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-08-14 10:22:31 -04:00
|
|
|
});
|
2020-05-15 09:49:11 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-05-15 09:49:11 -04:00
|
|
|
name: "strict pass case",
|
|
|
|
fn(): void {
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStrictEquals(true, true);
|
|
|
|
assertStrictEquals(10, 10);
|
|
|
|
assertStrictEquals("abc", "abc");
|
2020-05-15 09:49:11 -04:00
|
|
|
|
|
|
|
const xs = [1, false, "foo"];
|
|
|
|
const ys = xs;
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStrictEquals(xs, ys);
|
2020-05-15 09:49:11 -04:00
|
|
|
|
|
|
|
const x = { a: 1 };
|
|
|
|
const y = x;
|
2020-06-05 23:43:00 -04:00
|
|
|
assertStrictEquals(x, y);
|
2020-05-15 09:49:11 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-05-15 09:49:11 -04:00
|
|
|
name: "strict failed with structure diff",
|
|
|
|
fn(): void {
|
|
|
|
assertThrows(
|
2020-06-05 23:43:00 -04:00
|
|
|
(): void => assertStrictEquals({ a: 1, b: 2 }, { a: 1, c: [3] }),
|
2020-05-15 09:49:11 -04:00
|
|
|
AssertionError,
|
|
|
|
[
|
|
|
|
"Values are not strictly equal:",
|
|
|
|
...createHeader(),
|
2020-05-19 14:19:26 -04:00
|
|
|
removed(`- { a: ${yellow("1")}, b: ${yellow("2")} }`),
|
|
|
|
added(`+ { a: ${yellow("1")}, c: [ ${yellow("3")} ] }`),
|
2020-05-15 09:49:11 -04:00
|
|
|
"",
|
|
|
|
].join("\n")
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-05-15 09:49:11 -04:00
|
|
|
name: "strict failed with reference diff",
|
|
|
|
fn(): void {
|
|
|
|
assertThrows(
|
2020-06-05 23:43:00 -04:00
|
|
|
(): void => assertStrictEquals({ a: 1, b: 2 }, { a: 1, b: 2 }),
|
2020-05-15 09:49:11 -04:00
|
|
|
AssertionError,
|
|
|
|
[
|
|
|
|
"Values have the same structure but are not reference-equal:\n",
|
2020-05-19 14:19:26 -04:00
|
|
|
red(` { a: ${yellow("1")}, b: ${yellow("2")} }`),
|
2020-05-15 09:49:11 -04:00
|
|
|
].join("\n")
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2020-06-23 10:47:09 -04:00
|
|
|
|
|
|
|
Deno.test("Assert Throws Non-Error Fail", () => {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
throw "Panic!";
|
|
|
|
},
|
|
|
|
String,
|
|
|
|
"Panic!"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown."
|
|
|
|
);
|
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
assertThrows(() => {
|
|
|
|
throw null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown."
|
|
|
|
);
|
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
assertThrows(() => {
|
|
|
|
throw undefined;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown."
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("Assert Throws Async Non-Error Fail", () => {
|
|
|
|
assertThrowsAsync(
|
|
|
|
() => {
|
|
|
|
return assertThrowsAsync(
|
|
|
|
() => {
|
|
|
|
return Promise.reject("Panic!");
|
|
|
|
},
|
|
|
|
String,
|
|
|
|
"Panic!"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown or rejected."
|
|
|
|
);
|
|
|
|
|
|
|
|
assertThrowsAsync(
|
|
|
|
() => {
|
|
|
|
return assertThrowsAsync(() => {
|
|
|
|
return Promise.reject(null);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown or rejected."
|
|
|
|
);
|
|
|
|
|
|
|
|
assertThrowsAsync(
|
|
|
|
() => {
|
|
|
|
return assertThrowsAsync(() => {
|
|
|
|
return Promise.reject(undefined);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown or rejected."
|
|
|
|
);
|
|
|
|
|
|
|
|
assertThrowsAsync(
|
|
|
|
() => {
|
|
|
|
return assertThrowsAsync(() => {
|
|
|
|
throw undefined;
|
|
|
|
return Promise.resolve("Ok!");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"A non-Error object was thrown or rejected."
|
|
|
|
);
|
|
|
|
});
|