diff options
author | Xin Du (Clark) <clark.duxin@gmail.com> | 2019-06-05 19:35:35 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-05 14:35:35 -0400 |
commit | 33b6055f5f38c8114ab8557386e66bb99174edc3 (patch) | |
tree | c05019ce5d56295d139740225caaf921f6933f14 | |
parent | 21684c679bf64c4e17bdab03d10ac12cdca56b3c (diff) |
datetime: use assertThrows in test (denoland/deno_std#473)
Original: https://github.com/denoland/deno_std/commit/3041edb152e9215952c1c69522d3dedb2b345428
-rw-r--r-- | datetime/test.ts | 32 |
1 files changed, 17 insertions, 15 deletions
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 { |