I would like to know the proper way to compare objects in a unit test. For the purpose of this example, I am using assert
and mocha
to test a simple library mylib
with a method method
that returns an object.
var assert = require("assert");
var mylib = require("../src/mylib");
describe("method", function() {
it("does something clever and returns an object", function() {
assert.equal(
JSON.stringify({/* expected object */}),
JSON.stringify(mylib.method(["items", "in", "the", "list"])));
});
});
The above works, but I don't know if using JSON.stringify
is a recommended practice. Am I doing this right?
Aucun commentaire:
Enregistrer un commentaire