Skip to content

Commit

Permalink
Merge pull request #1234 from tulios/bigint-logging-1233
Browse files Browse the repository at this point in the history
Fix TypeError on logging BigInt
  • Loading branch information
Nevon authored Nov 22, 2021
2 parents 812e055 + 3e5eded commit 191962a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/long.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Long {
}

/**
* Converts the Long to a string written in the specified radix.
* Converts the Long to a string.
* @returns {string}
* @override
*/
Expand All @@ -119,6 +119,15 @@ class Long {
return Number(BigInt.asIntN(32, this.value))
}

/**
* Converts the Long to JSON
* @returns {string}
* @override
*/
toJSON() {
return this.toString()
}

/**
* Returns this Long with bits shifted to the left by the given amount.
* @param {number|bigint} numBits Number of bits
Expand Down
8 changes: 8 additions & 0 deletions src/utils/long.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ describe('Utils > Long', () => {
expect(expectedNumber).toEqual(9223372036854776000)
expect(typeof expectedNumber).toEqual('number')
})

describe('toJSON()', () => {
it('should return a string', () => {
const serialized = max.toJSON()

expect(serialized).toEqual('9223372036854775807')
})
})
})

describe('Operators', () => {
Expand Down

0 comments on commit 191962a

Please sign in to comment.