Skip to content

Commit

Permalink
tests(fmt): add duration() tests (#4551)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmtj authored Apr 7, 2024
1 parent 0342613 commit 7fe7e31
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion fmt/duration_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertExists } from "../assert/mod.ts";
import { assertEquals, assertExists, assertThrows } from "../assert/mod.ts";
import { format } from "./duration.ts";

Deno.test({
Expand Down Expand Up @@ -63,9 +63,32 @@ Deno.test({
},
});

Deno.test({
name: "format() handles digital style ignore zero",
fn() {
assertEquals(
format(99674, { ignoreZero: true, style: "digital" }),
"00:00:01:39:674",
);
},
});

Deno.test({
name: "format() handles duration rounding error",
fn() {
assertEquals(format(16.342, { ignoreZero: true }), "16ms 342µs");
},
});

Deno.test({
name: "format() handles default style error",
fn() {
assertThrows(
() => {
format(16.342, { style: undefined });
},
TypeError,
`style must be "narrow", "full", or "digital"!`,
);
},
});

0 comments on commit 7fe7e31

Please sign in to comment.