Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-temporal.duration.compare
7 description: relativeTo property bag with offset property is rejected if offset is in the wrong format
8 features: [Temporal]
9 ---*/
10
11 const d1 = new Temporal.Duration(0, 1, 0, 280);
12 const d2 = new Temporal.Duration(0, 1, 0, 281);
13
14 const badOffsets = [
15 "00:00", // missing sign
16 "+0", // too short
17 "-000:00", // too long
18 1000, // must be a string
19 null, // must be a string
20 true, // must be a string
21 1000n, // must be a string
22 ];
23 badOffsets.forEach((offset) => {
24 const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone: "UTC" };
25 assert.throws(
26 typeof(offset) === 'string' ? RangeError : TypeError,
27 () => Temporal.Duration.compare(d1, d2, { relativeTo }),
28 `"${offset} is not a valid offset string`
29 );
30 });
31
32 reportCompare(0, 0);