Browse Source

add tests for json parse/stringify of bigints

pull/17/head
Brett Langdon 11 years ago
parent
commit
a781bc63e1
2 changed files with 30 additions and 2 deletions
  1. +4
    -2
      package.json
  2. +26
    -0
      test/json.js

+ 4
- 2
package.json View File

@ -4,7 +4,7 @@
"description": "Datadog API Node.JS Client",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "./node_modules/.bin/mocha ./test",
"docs": "node ./docs/create.js > index.html"
},
"bin": {
@ -38,9 +38,11 @@
"rc": "^1.0.0"
},
"devDependencies": {
"bignumber.js": "^2.0.7",
"docast": "^0.1.1",
"glob": "^5.0.3",
"js-yaml": "^3.2.7",
"marked": "^0.3.3"
"marked": "^0.3.3",
"mocha": "^2.2.5"
}
}

+ 26
- 0
test/json.js View File

@ -0,0 +1,26 @@
var assert = require("assert");
var BigNumber = require("bignumber.js");
var json = require("../lib/json");
describe("json", function(){
describe("#parse()", function(){
it("should properly parse big integers", function(){
// DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16
var data = "{\"id\": 2868860079149422351}";
var parsed = json.parse(data);
// `parsed.id` is an instance of `BigNumber`
assert.equal(parsed.id.toString(), "2868860079149422351");
});
});
describe("#stringify()", function(){
it("should properly parse big integers", function(){
// DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16
var data = {"id": new BigNumber('2868860079149422351')};
var stringified = json.stringify(data);
// Yeah, it ends up being a string and not an int, but mostly we
// want to make sure it doesn't throw an error or provide the wrong number
assert.equal(stringified, "{\"id\":\"2868860079149422351\"}");
});
});
});

Loading…
Cancel
Save