summaryrefslogtreecommitdiff
path: root/testing/asserts_test.ts
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-03-08 22:04:43 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-08 16:04:43 -0500
commit831d74e364b634eab4f587f30570e17c8c54c17e (patch)
treebe309ef55902e552fdd6ad2403c208096e9f4fde /testing/asserts_test.ts
parent3761d41d32d6e6baffa56adbda380d04ad10e710 (diff)
Use AssertionError instead of Error in testing (denoland/deno_std#254)
Original: https://github.com/denoland/deno_std/commit/d4088a1920d005132bce2b0cd948ed74e0250563
Diffstat (limited to 'testing/asserts_test.ts')
-rw-r--r--testing/asserts_test.ts27
1 files changed, 22 insertions, 5 deletions
diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts
index ccec2af09..6f82d4169 100644
--- a/testing/asserts_test.ts
+++ b/testing/asserts_test.ts
@@ -2,20 +2,19 @@
import {
assert,
- equal,
assertNotEquals,
assertStrContains,
assertArrayContains,
assertMatch,
assertEquals,
+ assertThrows,
+ AssertionError,
+ equal,
+ fail,
unimplemented,
unreachable
} from "./asserts.ts";
import { test } from "./mod.ts";
-// import { assertEquals as prettyAssertEqual } from "./pretty.ts";
-// import "./format_test.ts";
-// import "./diff_test.ts";
-// import "./pretty_test.ts";
test(function testingEqual() {
assert(equal("world", "world"));
@@ -49,6 +48,7 @@ test(function testingNotEquals() {
assertNotEquals("Raptor", "Raptor");
didThrow = false;
} catch (e) {
+ assert(e instanceof AssertionError);
didThrow = true;
}
assertEquals(didThrow, true);
@@ -63,6 +63,7 @@ test(function testingAssertStringContains() {
assertStrContains("Denosaurus", "Raptor");
didThrow = false;
} catch (e) {
+ assert(e instanceof AssertionError);
didThrow = true;
}
assertEquals(didThrow, true);
@@ -78,6 +79,7 @@ test(function testingArrayContains() {
assertArrayContains(fixtureObject, [{ deno: "node" }]);
didThrow = false;
} catch (e) {
+ assert(e instanceof AssertionError);
didThrow = true;
}
assertEquals(didThrow, true);
@@ -92,6 +94,7 @@ test(function testingAssertStringContainsThrow() {
e.message ===
`actual: "Denosaurus from Jurassic" expected to contains: "Raptor"`
);
+ assert(e instanceof AssertionError);
didThrow = true;
}
assert(didThrow);
@@ -110,6 +113,7 @@ test(function testingAssertStringMatchingThrows() {
e.message ===
`actual: "Denosaurus from Jurassic" expected to match: "/Raptor/"`
);
+ assert(e instanceof AssertionError);
didThrow = true;
}
assert(didThrow);
@@ -121,6 +125,7 @@ test(function testingAssertsUnimplemented() {
unimplemented();
} catch (e) {
assert(e.message === "unimplemented");
+ assert(e instanceof AssertionError);
didThrow = true;
}
assert(didThrow);
@@ -132,7 +137,19 @@ test(function testingAssertsUnreachable() {
unreachable();
} catch (e) {
assert(e.message === "unreachable");
+ assert(e instanceof AssertionError);
didThrow = true;
}
assert(didThrow);
});
+
+test(function testingAssertFail() {
+ assertThrows(fail, AssertionError, "Failed assertion.");
+ assertThrows(
+ () => {
+ fail("foo");
+ },
+ AssertionError,
+ "Failed assertion: foo"
+ );
+});