I am working on writing a testing suite for our REST API in node.js. I am wondering if there is a module out there that does the json comparison in a configurable way.
For example : { "id":"456", "data":"Test_Data", "date":"2014-05-19" }
I need to be able to tell the module, check not null for id since its autogenerated, check not null for date and check only data value.
Thanks.
Or you can use expect.js
var expect = require("expect.js");
var data = {"name":"John", "age":32};
data.toString = function(){"String"};
expect(data).not.to.be(undefined);
expect(data.name).to.be("John");
expect(data.toString).to.be.a("function");
For your tests, you can use should.js:
var should = require('should');
var data = { "id":"456", "data":"Test_Data", "date":"2014-05-19" };
data.should.containEql({ id: "456" })
data.should.have.property("data");
data.should.have.property("data").with.type("string");
data.should.not.have.property("non-existing");
data.data.should.match(/^Test.*$/);
[...]
Happy testing!
EDIT: you can use instead of use. Also, I'm not affiliated with should.js :)