constructor-options-dayPeriod-invalid.js (803B)
1 // Copyright 2019 Google Inc. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-createdatetimeformat 6 description: > 7 Checks error cases for the options argument to the DateTimeFormat constructor. 8 info: | 9 [[DayPeriod]] `"dayPeriod"` `"narrow"`, `"short"`, `"long"` 10 CreateDateTimeFormat ( dateTimeFormat, locales, options, required, defaults ) 11 12 ... 13 features: [Intl.DateTimeFormat-dayPeriod] 14 ---*/ 15 16 const invalidOptions = [ 17 "", 18 "LONG", 19 " long", 20 "short ", 21 "full", 22 "numeric", 23 ]; 24 for (const dayPeriod of invalidOptions) { 25 assert.throws(RangeError, function() { 26 new Intl.DateTimeFormat("en", { dayPeriod }); 27 }, `new Intl.DateTimeFormat("en", { dayPeriod: "${dayPeriod}" }) throws RangeError`); 28 } 29 30 reportCompare(0, 0);