test262/test/built-ins/Temporal/PlainMonthDay/from/calendar-fields-iterable.js

31 lines
1.1 KiB
JavaScript

// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plainmonthday.from
description: Verify the result of calendar.fields() is treated correctly.
info: |
sec-temporal.plainmonthday.from step 3:
3. Return ? ToTemporalMonthDay(_item_, _options_).
sec-temporal-totemporalmonthday step 2.f:
f. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"*, *"monthCode"*, *"year"* »).
sec-temporal-calendarfields step 4:
4. Let _result_ be ? IterableToList(_fieldsArray_).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"day",
"month",
"monthCode",
"year",
];
const calendar = TemporalHelpers.calendarFieldsIterable();
Temporal.PlainMonthDay.from({ monthCode: "M05", day: 2, calendar });
assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once");
assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args");
assert(calendar.iteratorExhausted[0], "iterated through the whole iterable");