summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-02 21:31:41 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-08 00:07:18 +0100
commit97cc8f461349d67050164ce6fd821cdca5188167 (patch)
tree9c7c9ff00e59bb6dda982693a8fd00f03ad0c730 /Userland/Libraries/LibJS/Tests
parentfb7b4caa574e8d4ad72657525590c5076d97a65a (diff)
downloadserenity-97cc8f461349d67050164ce6fd821cdca5188167.zip
LibJS: Validate Calendar.prototype.fields() values more strictly
This is a normative change in the Temporal spec. See: - https://github.com/tc39/proposal-temporal/commit/75b66d8 - https://github.com/tc39/proposal-temporal/commit/9c2262b
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.fields.js29
1 files changed, 27 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.fields.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.fields.js
index 714f978ccf..09214fc2be 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.fields.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.fields.js
@@ -5,7 +5,18 @@ describe("correct behavior", () => {
test("basic functionality", () => {
const calendar = new Temporal.Calendar("iso8601");
- const array = ["foo", "bar", "baz"];
+ const array = [
+ "year",
+ "month",
+ "monthCode",
+ "day",
+ "hour",
+ "minute",
+ "second",
+ "millisecond",
+ "microsecond",
+ "nanosecond",
+ ];
const fields = calendar.fields(array);
expect(fields).toEqual(array);
expect(fields).not.toBe(array);
@@ -24,7 +35,21 @@ describe("errors", () => {
for (const value of [123, null, undefined, true, {}]) {
expect(() => {
calendar.fields([value]);
- }).toThrowWithMessage(TypeError, "FIXME: Add a string for this error.");
+ }).toThrowWithMessage(TypeError, `Invalid calendar field ${value}, expected a string`);
}
});
+
+ test("iterator values must be valid field names", () => {
+ const calendar = new Temporal.Calendar("iso8601");
+ expect(() => {
+ calendar.fields(["foo"]);
+ }).toThrowWithMessage(RangeError, "Invalid calendar field 'foo'");
+ });
+
+ test("iterator values must not contain duplicates", () => {
+ const calendar = new Temporal.Calendar("iso8601");
+ expect(() => {
+ calendar.fields(["year", "month", "year", "month"]);
+ }).toThrowWithMessage(RangeError, "Duplicate calendar field 'year'");
+ });
});