mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +00:00
LibJS: Add tests for calendar fields of DateTimeFormat's resolvedOptions
These are (mostly) testable now that LibUnicode parses format patterns.
This commit is contained in:
parent
e42d954743
commit
20b6ffef4f
1 changed files with 73 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
// NOTE: We cannot yet test the fields of ECMA-402's Table 4 (week, day, etc.) because those fields
|
// NOTE: We cannot yet test the fractionalSecondDigits option. There aren't any patterns in the CLDR
|
||||||
// won't be copied into the Intl.DateTimeFormat object until the date-time pattern generator
|
// with this field ('S' in https://unicode.org/reports/tr35/tr35-dates.html#dfst-second). We
|
||||||
// actually parses the CLDR patterns (see parse_date_time_pattern).
|
// will need to figure out how this field should be generated.
|
||||||
describe("correct behavior", () => {
|
describe("correct behavior", () => {
|
||||||
test("length is 0", () => {
|
test("length is 0", () => {
|
||||||
expect(Intl.DateTimeFormat.prototype.resolvedOptions).toHaveLength(0);
|
expect(Intl.DateTimeFormat.prototype.resolvedOptions).toHaveLength(0);
|
||||||
|
@ -115,4 +115,74 @@ describe("correct behavior", () => {
|
||||||
expect(el.resolvedOptions().timeStyle).toBe(style);
|
expect(el.resolvedOptions().timeStyle).toBe(style);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("weekday", () => {
|
||||||
|
["narrow", "short", "long"].forEach(weekday => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { weekday: weekday });
|
||||||
|
expect(en.resolvedOptions().weekday).toBe(weekday);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("era", () => {
|
||||||
|
["narrow", "short", "long"].forEach(era => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { era: era });
|
||||||
|
expect(en.resolvedOptions().era).toBe(era);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("year", () => {
|
||||||
|
["2-digit", "numeric"].forEach(year => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { year: year });
|
||||||
|
expect(en.resolvedOptions().year).toBe(year);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("month", () => {
|
||||||
|
["2-digit", "numeric", "narrow", "short", "long"].forEach(month => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { month: month });
|
||||||
|
expect(en.resolvedOptions().month).toBe(month);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("day", () => {
|
||||||
|
["2-digit", "numeric"].forEach(day => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { day: day });
|
||||||
|
expect(en.resolvedOptions().day).toBe(day);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("dayPeriod", () => {
|
||||||
|
["narrow", "short", "long"].forEach(dayPeriod => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { dayPeriod: dayPeriod });
|
||||||
|
expect(en.resolvedOptions().dayPeriod).toBe(dayPeriod);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("hour", () => {
|
||||||
|
["2-digit", "numeric"].forEach(hour => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { hour: hour });
|
||||||
|
expect(en.resolvedOptions().hour).toBe(hour);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("minute", () => {
|
||||||
|
["2-digit", "numeric"].forEach(minute => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { minute: minute });
|
||||||
|
expect(en.resolvedOptions().minute).toBe(minute);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("second", () => {
|
||||||
|
["2-digit", "numeric"].forEach(second => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { second: second });
|
||||||
|
expect(en.resolvedOptions().second).toBe(second);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("timeZoneName", () => {
|
||||||
|
["short", "long"].forEach(timeZoneName => {
|
||||||
|
const en = new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName });
|
||||||
|
expect(en.resolvedOptions().timeZoneName).toBe(timeZoneName);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue