Skip to content

Commit

Permalink
Added Additional Unit Tests for English.js (#1672)
Browse files Browse the repository at this point in the history
* added unit tests

* clean up before creating PR

* clean up before creating PR

* clean up
  • Loading branch information
danielhwile authored Jan 17, 2025
1 parent 3e9983c commit 0d267fa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 51 additions & 2 deletions test/impl/english.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global test expect */

import { formatRelativeTime } from "../../src/impl/english";
import * as Formats from "../../src/impl/formats";
import { formatRelativeTime, formatString, weekdays, eras } from "../../src/impl/english";

test("today", () => {
expect(formatRelativeTime("days", 0, "auto")).toBe("today");
Expand Down Expand Up @@ -79,3 +79,52 @@ test("1 hour ago", () => {
expect(formatRelativeTime("hours", -1, "always")).toBe("1 hour ago");
expect(formatRelativeTime("hours", -1, "always", true)).toBe("1 hr. ago");
});

test("formatString", () => {
expect(formatString(Formats.DATE_SHORT)).toBe("M/d/yyyy");
expect(formatString(Formats.DATE_MED)).toBe("LLL d, yyyy");
expect(formatString(Formats.DATE_MED_WITH_WEEKDAY)).toBe("EEE, LLL d, yyyy");
expect(formatString(Formats.DATE_FULL)).toBe("LLLL d, yyyy");
expect(formatString(Formats.DATE_HUGE)).toBe("EEEE, LLLL d, yyyy");
expect(formatString(Formats.TIME_SIMPLE)).toBe("h:mm a");
expect(formatString(Formats.TIME_WITH_SECONDS)).toBe("h:mm:ss a");
expect(formatString(Formats.TIME_WITH_SHORT_OFFSET)).toBe("h:mm a");
expect(formatString(Formats.TIME_WITH_LONG_OFFSET)).toBe("h:mm a");
expect(formatString(Formats.TIME_24_SIMPLE)).toBe("HH:mm");
expect(formatString(Formats.TIME_24_WITH_SECONDS)).toBe("HH:mm:ss");
expect(formatString(Formats.TIME_24_WITH_SHORT_OFFSET)).toBe("HH:mm");
expect(formatString(Formats.TIME_24_WITH_LONG_OFFSET)).toBe("HH:mm");
expect(formatString(Formats.DATETIME_SHORT)).toBe("M/d/yyyy, h:mm a");
expect(formatString(Formats.DATETIME_MED)).toBe("LLL d, yyyy, h:mm a");
expect(formatString(Formats.DATETIME_FULL)).toBe("LLLL d, yyyy, h:mm a");
expect(formatString(Formats.DATETIME_HUGE)).toBe("EEEE, LLLL d, yyyy, h:mm a");
expect(formatString(Formats.DATETIME_SHORT_WITH_SECONDS)).toBe("M/d/yyyy, h:mm:ss a");
expect(formatString(Formats.DATETIME_MED_WITH_SECONDS)).toBe("LLL d, yyyy, h:mm:ss a");
expect(formatString(Formats.DATETIME_MED_WITH_WEEKDAY)).toBe("EEE, d LLL yyyy, h:mm a");
expect(formatString(Formats.DATETIME_FULL_WITH_SECONDS)).toBe("LLLL d, yyyy, h:mm:ss a");
expect(formatString(Formats.DATETIME_HUGE_WITH_SECONDS)).toBe("EEEE, LLLL d, yyyy, h:mm:ss a");
expect(formatString("Default")).toBe("EEEE, LLLL d, yyyy, h:mm a");
});

test("weekdays", () => {
expect(weekdays("narrow")).toStrictEqual(["M", "T", "W", "T", "F", "S", "S"]);
expect(weekdays("short")).toStrictEqual(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]);
expect(weekdays("long")).toStrictEqual([
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
]);
expect(weekdays("numeric")).toStrictEqual(["1", "2", "3", "4", "5", "6", "7"]);
expect(weekdays(null)).toStrictEqual(null);
});

test("eras", () => {
expect(eras("narrow")).toStrictEqual(["B", "A"]);
expect(eras("short")).toStrictEqual(["BC", "AD"]);
expect(eras("long")).toStrictEqual(["Before Christ", "Anno Domini"]);
expect(eras("default")).toStrictEqual(null);
});

0 comments on commit 0d267fa

Please sign in to comment.