Skip to content

Commit 2268937

Browse files
committed
add a few tests for scalars
1 parent de76b9c commit 2268937

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/type/__tests__/scalars-test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Type System: Specified scalar types', () => {
2121
expect(parseValue(1)).to.equal(1);
2222
expect(parseValue(0)).to.equal(0);
2323
expect(parseValue(-1)).to.equal(-1);
24+
expect(parseValue(1n)).to.equal(1);
2425

2526
expect(() => parseValue(9876504321)).to.throw(
2627
'Int cannot represent non 32-bit signed integer value: 9876504321',
@@ -119,6 +120,7 @@ describe('Type System: Specified scalar types', () => {
119120
expect(serialize(1e5)).to.equal(100000);
120121
expect(serialize(false)).to.equal(0);
121122
expect(serialize(true)).to.equal(1);
123+
expect(serialize(1n)).to.equal(1);
122124

123125
const customValueOfObj = {
124126
value: 5,
@@ -280,6 +282,7 @@ describe('Type System: Specified scalar types', () => {
280282
expect(serialize('-1.1')).to.equal(-1.1);
281283
expect(serialize(false)).to.equal(0.0);
282284
expect(serialize(true)).to.equal(1.0);
285+
expect(serialize(1n)).to.equal(1n);
283286

284287
const customValueOfObj = {
285288
value: 5.5,
@@ -380,6 +383,7 @@ describe('Type System: Specified scalar types', () => {
380383
expect(serialize(-1.1)).to.equal('-1.1');
381384
expect(serialize(true)).to.equal('true');
382385
expect(serialize(false)).to.equal('false');
386+
expect(serialize(9007199254740993n)).to.equal('9007199254740993');
383387

384388
const valueOf = () => 'valueOf string';
385389
const toJSON = () => 'toJSON string';
@@ -493,6 +497,8 @@ describe('Type System: Specified scalar types', () => {
493497

494498
expect(serialize(1)).to.equal(true);
495499
expect(serialize(0)).to.equal(false);
500+
expect(serialize(1n)).to.equal(true);
501+
expect(serialize(0n)).to.equal(false);
496502
expect(serialize(true)).to.equal(true);
497503
expect(serialize(false)).to.equal(false);
498504
expect(
@@ -539,6 +545,9 @@ describe('Type System: Specified scalar types', () => {
539545
expect(parseValue(9007199254740991)).to.equal('9007199254740991');
540546
expect(parseValue(-9007199254740991)).to.equal('-9007199254740991');
541547

548+
// Can handle bigint in JS
549+
expect(parseValue(9007199254740993n)).to.equal('9007199254740993');
550+
542551
expect(() => parseValue(undefined)).to.throw(
543552
'ID cannot represent value: undefined',
544553
);
@@ -614,6 +623,7 @@ describe('Type System: Specified scalar types', () => {
614623
expect(serialize(123)).to.equal('123');
615624
expect(serialize(0)).to.equal('0');
616625
expect(serialize(-1)).to.equal('-1');
626+
expect(serialize(9007199254740993n)).to.equal('9007199254740993');
617627

618628
const valueOf = () => 'valueOf ID';
619629
const toJSON = () => 'toJSON ID';

0 commit comments

Comments
 (0)