From 33b6055f5f38c8114ab8557386e66bb99174edc3 Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Wed, 5 Jun 2019 19:35:35 +0100 Subject: datetime: use assertThrows in test (denoland/deno_std#473) Original: https://github.com/denoland/deno_std/commit/3041edb152e9215952c1c69522d3dedb2b345428 --- datetime/test.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'datetime') diff --git a/datetime/test.ts b/datetime/test.ts index 2c34e4fe8..ecf844a41 100644 --- a/datetime/test.ts +++ b/datetime/test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { test } from "../testing/mod.ts"; -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../testing/asserts.ts"; import * as datetime from "./mod.ts"; test(function parseDateTime(): void { @@ -31,13 +31,14 @@ test(function parseDateTime(): void { }); test(function invalidParseDateTimeFormatThrows(): void { - try { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (datetime as any).parseDateTime("2019-01-01 00:00", "x-y-z"); - assert(false, "no exception was thrown"); - } catch (e) { - assertEquals(e.message, "Invalid datetime format!"); - } + assertThrows( + (): void => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (datetime as any).parseDateTime("2019-01-01 00:00", "x-y-z"); + }, + Error, + "Invalid datetime format!" + ); }); test(function parseDate(): void { @@ -56,13 +57,14 @@ test(function parseDate(): void { }); test(function invalidParseDateFormatThrows(): void { - try { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (datetime as any).parseDate("2019-01-01", "x-y-z"); - assert(false, "no exception was thrown"); - } catch (e) { - assertEquals(e.message, "Invalid date format!"); - } + assertThrows( + (): void => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (datetime as any).parseDate("2019-01-01", "x-y-z"); + }, + Error, + "Invalid date format!" + ); }); test(function DayOfYear(): void { -- cgit v1.2.3