Add tests for Temporal.now.instant (#3031)

This commit is contained in:
jugglinmike 2021-06-29 11:45:42 -04:00 committed by GitHub
parent ebb6c34fa5
commit aaf4402b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 0 deletions

View File

@ -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));

View File

@ -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,
});

View File

@ -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
});

View File

@ -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');

View File

@ -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
});

View File

@ -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);

View File

@ -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
);

View File

@ -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');