Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Temporal.now.instant #3031

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/built-ins/Temporal/now/instant/extensible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: Temporal.now.instant is extensible.
features: [Temporal]
---*/

assert(Object.isExtensible(Temporal.now.instant));
15 changes: 15 additions & 0 deletions test/built-ins/Temporal/now/instant/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: Temporal.now.instant.length is 0
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.now.instant, "length", {
value: 0,
writable: false,
enumerable: false,
configurable: true,
});
16 changes: 16 additions & 0 deletions test/built-ins/Temporal/now/instant/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: Temporal.now.instant.name is "instant".
includes: [propertyHelper.js]
features: [Temporal]
---*/

assert.sameValue(Temporal.now.instant.name, 'instant');

verifyProperty(Temporal.now.instant, 'name', {
enumerable: false,
writable: false,
configurable: true
});
14 changes: 14 additions & 0 deletions test/built-ins/Temporal/now/instant/not-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: Temporal.now.instant does not implement [[Construct]]
includes: [isConstructor.js]
features: [Reflect.construct, Temporal]
---*/

assert.sameValue(isConstructor(Temporal.now.instant), false, 'isConstructor(Temporal.now.instant) must return false');

assert.throws(TypeError, () => {
new Temporal.now.instant();
}, '`new Temporal.now.instant()` throws TypeError');
14 changes: 14 additions & 0 deletions test/built-ins/Temporal/now/instant/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: The "instant" property of Temporal.now
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.now, 'instant', {
enumerable: false,
writable: true,
configurable: true
});
12 changes: 12 additions & 0 deletions test/built-ins/Temporal/now/instant/return-value-distinct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: Each invocation of the function produces a distinct object value
features: [Temporal]
---*/

var instant1 = Temporal.now.instant();
var instant2 = Temporal.now.instant();

assert.notSameValue(instant1, instant2);
12 changes: 12 additions & 0 deletions test/built-ins/Temporal/now/instant/return-value-prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: Temporal.now.instant returns an instance of the Instant constructor
features: [Temporal]
---*/

assert.sameValue(
Object.getPrototypeOf(Temporal.now.instant()),
Temporal.Instant.prototype
);
16 changes: 16 additions & 0 deletions test/built-ins/Temporal/now/instant/return-value-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.instant
description: >
Temporal.now.instant returns an Instant describing the current moment in time
(as corroborated by `Date.now`)
features: [Temporal, BigInt]
---*/

var nowBefore = Date.now();
var seconds = Number(Temporal.now.instant().epochNanoseconds / 1000000n);
var nowAfter = Date.now();

assert(seconds >= nowBefore, 'before');
assert(seconds <= nowAfter, 'after');