summaryrefslogtreecommitdiff
path: root/testing/test.ts
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-03-06 22:39:50 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-06 16:39:50 -0500
commite36edfdb3fd4709358a5f499f13cfe3d53c2b4f7 (patch)
tree1baef3f876a5e75288c3ec9056cdb93dd6b5787f /testing/test.ts
parentd29957ad17956016c35a04f5f1f98565e58e8a2e (diff)
Testing refactor (denoland/deno_std#240)
Original: https://github.com/denoland/deno_std/commit/e1d5c00279132aa639030c6c6d9b4e308bd4775e
Diffstat (limited to 'testing/test.ts')
-rw-r--r--testing/test.ts82
1 files changed, 30 insertions, 52 deletions
diff --git a/testing/test.ts b/testing/test.ts
index bdebce431..e3fc5c431 100644
--- a/testing/test.ts
+++ b/testing/test.ts
@@ -1,45 +1,23 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { test, assert, assertEqual, equal, runIfMain } from "./mod.ts";
-import { assertEqual as prettyAssertEqual } from "./pretty.ts";
+import { test, runIfMain } from "./mod.ts";
+import {
+ assert,
+ assertEq,
+ assertStrictEq,
+ assertThrows,
+ assertThrowsAsync,
+ fail
+} from "../testing/asserts.ts";
import "./format_test.ts";
import "./diff_test.ts";
import "./pretty_test.ts";
import "./asserts_test.ts";
-test(function testingEqual() {
- 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" } }
- )
- );
-});
-
-test(function testingAssertEqual() {
- const a = Object.create(null);
- a.b = "foo";
- assert.equal(a, a);
- assert(assertEqual === prettyAssertEqual);
-});
-
test(function testingAssertFail() {
- assert.throws(assert.fail, Error, "Failed assertion.");
- assert.throws(
+ assertThrows(fail, Error, "Failed assertion.");
+ assertThrows(
() => {
- assert.fail("foo");
+ fail("foo");
},
Error,
"Failed assertion: foo"
@@ -50,7 +28,7 @@ test(function testingAssertEqualActualUncoercable() {
let didThrow = false;
const a = Object.create(null);
try {
- assert.equal(a, "bar");
+ assertEq(a, "bar");
} catch (e) {
didThrow = true;
}
@@ -61,7 +39,7 @@ test(function testingAssertEqualExpectedUncoercable() {
let didThrow = false;
const a = Object.create(null);
try {
- assert.equal("bar", a);
+ assertStrictEq("bar", a);
} catch (e) {
didThrow = true;
}
@@ -71,7 +49,7 @@ test(function testingAssertEqualExpectedUncoercable() {
test(function testingAssertStrictEqual() {
const a = {};
const b = a;
- assert.strictEqual(a, b);
+ assertStrictEq(a, b);
});
test(function testingAssertNotStrictEqual() {
@@ -79,7 +57,7 @@ test(function testingAssertNotStrictEqual() {
const a = {};
const b = {};
try {
- assert.strictEqual(a, b);
+ assertStrictEq(a, b);
} catch (e) {
assert(e.message === "actual: [object Object] expected: [object Object]");
didThrow = true;
@@ -89,7 +67,7 @@ test(function testingAssertNotStrictEqual() {
test(function testingDoesThrow() {
let count = 0;
- assert.throws(() => {
+ assertThrows(() => {
count++;
throw new Error();
});
@@ -100,7 +78,7 @@ test(function testingDoesNotThrow() {
let count = 0;
let didThrow = false;
try {
- assert.throws(() => {
+ assertThrows(() => {
count++;
console.log("Hello world");
});
@@ -114,7 +92,7 @@ test(function testingDoesNotThrow() {
test(function testingThrowsErrorType() {
let count = 0;
- assert.throws(() => {
+ assertThrows(() => {
count++;
throw new TypeError();
}, TypeError);
@@ -125,7 +103,7 @@ test(function testingThrowsNotErrorType() {
let count = 0;
let didThrow = false;
try {
- assert.throws(() => {
+ assertThrows(() => {
count++;
throw new TypeError();
}, RangeError);
@@ -139,7 +117,7 @@ test(function testingThrowsNotErrorType() {
test(function testingThrowsMsgIncludes() {
let count = 0;
- assert.throws(
+ assertThrows(
() => {
count++;
throw new TypeError("Hello world!");
@@ -154,7 +132,7 @@ test(function testingThrowsMsgNotIncludes() {
let count = 0;
let didThrow = false;
try {
- assert.throws(
+ assertThrows(
() => {
count++;
throw new TypeError("Hello world!");
@@ -175,7 +153,7 @@ test(function testingThrowsMsgNotIncludes() {
test(async function testingDoesThrowAsync() {
let count = 0;
- await assert.throwsAsync(async () => {
+ await assertThrowsAsync(async () => {
count++;
throw new Error();
});
@@ -184,7 +162,7 @@ test(async function testingDoesThrowAsync() {
test(async function testingDoesReject() {
let count = 0;
- await assert.throwsAsync(() => {
+ await assertThrowsAsync(() => {
count++;
return Promise.reject(new Error());
});
@@ -195,7 +173,7 @@ test(async function testingDoesNotThrowAsync() {
let count = 0;
let didThrow = false;
try {
- await assert.throwsAsync(async () => {
+ await assertThrowsAsync(async () => {
count++;
console.log("Hello world");
});
@@ -211,7 +189,7 @@ test(async function testingDoesNotRejectAsync() {
let count = 0;
let didThrow = false;
try {
- await assert.throwsAsync(() => {
+ await assertThrowsAsync(() => {
count++;
console.log("Hello world");
return Promise.resolve();
@@ -226,7 +204,7 @@ test(async function testingDoesNotRejectAsync() {
test(async function testingThrowsAsyncErrorType() {
let count = 0;
- await assert.throwsAsync(async () => {
+ await assertThrowsAsync(async () => {
count++;
throw new TypeError();
}, TypeError);
@@ -237,7 +215,7 @@ test(async function testingThrowsAsyncNotErrorType() {
let count = 0;
let didThrow = false;
try {
- await assert.throwsAsync(async () => {
+ await assertThrowsAsync(async () => {
count++;
throw new TypeError();
}, RangeError);
@@ -251,7 +229,7 @@ test(async function testingThrowsAsyncNotErrorType() {
test(async function testingThrowsAsyncMsgIncludes() {
let count = 0;
- await assert.throwsAsync(
+ await assertThrowsAsync(
async () => {
count++;
throw new TypeError("Hello world!");
@@ -266,7 +244,7 @@ test(async function testingThrowsAsyncMsgNotIncludes() {
let count = 0;
let didThrow = false;
try {
- await assert.throwsAsync(
+ await assertThrowsAsync(
async () => {
count++;
throw new TypeError("Hello world!");