source: imaps-frontend/node_modules/is-bigint/test/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[d565449]1'use strict';
2
3var test = require('tape');
4var inspect = require('object-inspect');
5var hasBigInts = require('has-bigints')();
6var hasToStringTag = require('has-tostringtag/shams')();
[79a0317]7var forEach = require('for-each');
8var v = require('es-value-fixtures');
[d565449]9
10var isBigInt = require('../');
11
12test('non-BigInt values', function (t) {
[79a0317]13 /** @type {(typeof v.primitives[number] | object)[]} */
14 var nonBigInts = v.nonBigInts.concat(
[d565449]15 Object(true),
16 Object(false),
[79a0317]17 // @ts-expect-error TS sucks with concat
[d565449]18 {},
19 [],
20 /a/g,
21 new Date(),
22 function () {},
[79a0317]23 NaN,
24 v.symbols
25 );
[d565449]26 t.plan(nonBigInts.length);
27 forEach(nonBigInts, function (nonBigInt) {
[79a0317]28 t.equal(false, isBigInt(nonBigInt), inspect(nonBigInt) + ' is not a BigInt');
[d565449]29 });
30 t.end();
31});
32
33test('faked BigInt values', function (t) {
34 t.test('real BigInt valueOf', { skip: !hasBigInts }, function (st) {
35 var fakeBigInt = { valueOf: function () { return BigInt(42); } };
36 st.equal(false, isBigInt(fakeBigInt), 'object with valueOf returning a BigInt is not a BigInt');
37 st.end();
38 });
39
40 t.test('faked @@toStringTag', { skip: !hasBigInts || !hasToStringTag }, function (st) {
[79a0317]41 /** @type {{ valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
[d565449]42 var fakeBigInt = { valueOf: function () { return BigInt(42); } };
43 fakeBigInt[Symbol.toStringTag] = 'BigInt';
44 st.equal(false, isBigInt(fakeBigInt), 'object with fake BigInt @@toStringTag and valueOf returning a BigInt is not a BigInt');
45
[79a0317]46 /** @type {{ valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
[d565449]47 var notSoFakeBigInt = { valueOf: function () { return 42; } };
48 notSoFakeBigInt[Symbol.toStringTag] = 'BigInt';
49 st.equal(false, isBigInt(notSoFakeBigInt), 'object with fake BigInt @@toStringTag and valueOf not returning a BigInt is not a BigInt');
50 st.end();
51 });
52
53 var fakeBigIntString = { toString: function () { return '42n'; } };
54 t.equal(false, isBigInt(fakeBigIntString), 'object with toString returning 42n is not a BigInt');
55
56 t.end();
57});
58
59test('BigInt support', { skip: !hasBigInts }, function (t) {
[79a0317]60 forEach(v.bigints.concat(Object(BigInt(42))), function (bigInt) {
61 t.equal(true, isBigInt(bigInt), inspect(bigInt) + ' is a BigInt');
[d565449]62 });
63
64 t.end();
65});
Note: See TracBrowser for help on using the repository browser.