1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-28 01:59:06 -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.
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 {