1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 16:13:18 +00:00
musix-oss/node_modules/json-bigint/test/bigint-test.js
2020-03-03 22:30:50 +02:00

32 lines
1.2 KiB
JavaScript

var mocha = require('mocha')
, assert = require('chai').assert
, expect = require('chai').expect
, BigNumber = require('bignumber.js')
;
describe("Testing bigint support", function(){
var input = '{"big":9223372036854775807,"small":123}';
it("Should show classic JSON.parse lacks bigint support", function(done){
var obj = JSON.parse(input);
expect(obj.small.toString(), "string from small int").to.equal("123");
expect(obj.big.toString(), "string from big int").to.not.equal("9223372036854775807");
var output = JSON.stringify(obj);
expect(output).to.not.equal(input);
done();
});
it("Should show JSNbig does support bigint parse/stringify roundtrip", function(done){
var JSONbig = require('../index');
var obj = JSONbig.parse(input);
expect(obj.small.toString(), "string from small int").to.equal("123");
expect(obj.big.toString(), "string from big int").to.equal("9223372036854775807");
expect(obj.big, "instanceof big int").to.be.instanceof(BigNumber);
var output = JSONbig.stringify(obj);
expect(output).to.equal(input);
done();
});
});