1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-28 10:09:20 -05:00
denoland-deno/testing/asserts_test.ts

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-03-05 14:58:28 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2019-03-06 16:39:50 -05:00
import { assert, equal, assertStrContains, assertMatch } from "./asserts.ts";
import { test } from "./mod.ts";
// import { assertEquals as prettyAssertEqual } from "./pretty.ts";
2019-03-05 14:58:28 -05:00
// import "./format_test.ts";
// import "./diff_test.ts";
// import "./pretty_test.ts";
2019-03-06 16:39:50 -05:00
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" } }
)
);
});
2019-03-05 14:58:28 -05:00
test(function testingAssertStringContains() {
assertStrContains("Denosaurus", "saur");
assertStrContains("Denosaurus", "Deno");
assertStrContains("Denosaurus", "rus");
});
test(function testingAssertStringContainsThrow() {
let didThrow = false;
try {
assertStrContains("Denosaurus from Jurassic", "Raptor");
} catch (e) {
assert(
e.message ===
`actual: "Denosaurus from Jurassic" expected to contains: "Raptor"`
);
didThrow = true;
}
assert(didThrow);
});
test(function testingAssertStringMatching() {
assertMatch("foobar@deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/));
});
test(function testingAssertStringMatchingThrows() {
let didThrow = false;
try {
assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/));
} catch (e) {
assert(
e.message ===
`actual: "Denosaurus from Jurassic" expected to match: "/Raptor/"`
);
didThrow = true;
}
assert(didThrow);
});