Skip to content

Commit

Permalink
Add tests for Temporal.now.instant (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored Jun 29, 2021
1 parent ebb6c34 commit aaf4402
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
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');

0 comments on commit aaf4402

Please sign in to comment.