From 787207f11bfcd657b93b47f2ffeb457cdd6f4eb0 Mon Sep 17 00:00:00 2001 From: Vincent LE GOFF Date: Tue, 5 Mar 2019 20:58:28 +0100 Subject: Refactor asserts in testing (denoland/deno_std#227) Original: https://github.com/denoland/deno_std/commit/c734e3234322cea5298a887373fe4ad1591d7c97 --- testing/asserts_test.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 testing/asserts_test.ts (limited to 'testing/asserts_test.ts') diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts new file mode 100644 index 000000000..f4256d8f5 --- /dev/null +++ b/testing/asserts_test.ts @@ -0,0 +1,46 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. + +import { assertStrContains, assertMatch } from "./asserts.ts"; +import { test, assert } from "./mod.ts"; +// import { assertEqual as prettyAssertEqual } from "./pretty.ts"; +// import "./format_test.ts"; +// import "./diff_test.ts"; +// import "./pretty_test.ts"; + +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); +}); -- cgit v1.2.3