1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 10:39:10 -05:00

datetime: use assertThrows in test (denoland/deno_std#473)

Original: 3041edb152
This commit is contained in:
Xin Du (Clark) 2019-06-05 19:35:35 +01:00 committed by Ryan Dahl
parent 21684c679b
commit 33b6055f5f

View file

@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts"; 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"; import * as datetime from "./mod.ts";
test(function parseDateTime(): void { test(function parseDateTime(): void {
@ -31,13 +31,14 @@ test(function parseDateTime(): void {
}); });
test(function invalidParseDateTimeFormatThrows(): void { test(function invalidParseDateTimeFormatThrows(): void {
try { assertThrows(
// eslint-disable-next-line @typescript-eslint/no-explicit-any (): void => {
(datetime as any).parseDateTime("2019-01-01 00:00", "x-y-z"); // eslint-disable-next-line @typescript-eslint/no-explicit-any
assert(false, "no exception was thrown"); (datetime as any).parseDateTime("2019-01-01 00:00", "x-y-z");
} catch (e) { },
assertEquals(e.message, "Invalid datetime format!"); Error,
} "Invalid datetime format!"
);
}); });
test(function parseDate(): void { test(function parseDate(): void {
@ -56,13 +57,14 @@ test(function parseDate(): void {
}); });
test(function invalidParseDateFormatThrows(): void { test(function invalidParseDateFormatThrows(): void {
try { assertThrows(
// eslint-disable-next-line @typescript-eslint/no-explicit-any (): void => {
(datetime as any).parseDate("2019-01-01", "x-y-z"); // eslint-disable-next-line @typescript-eslint/no-explicit-any
assert(false, "no exception was thrown"); (datetime as any).parseDate("2019-01-01", "x-y-z");
} catch (e) { },
assertEquals(e.message, "Invalid date format!"); Error,
} "Invalid date format!"
);
}); });
test(function DayOfYear(): void { test(function DayOfYear(): void {