I\'m just starting out writing tests for my AngularJS app and am doing so in Jasmine.
Here are the relevant code snippets
ClientController:
\
I just had a similar problem and implemented a custom matcher as follows, based on many approaches:
beforeEach(function() {
this.addMatchers({
toBeSimilarTo: function(expected) {
function buildObject(object) {
var built = {};
for (var name in object) {
if (object.hasOwnProperty(name)) {
built[name] = object[name];
}
}
return built;
}
var actualObject = buildObject(this.actual);
var expectedObject = buildObject(expected);
var notText = this.isNot ? " not" : "";
this.message = function () {
return "Expected " + actualObject + notText + " to be similar to " + expectedObject;
}
return jasmine.getEnv().equals_(actualObject, expectedObject);
}
});
});
and then used this way:
it("gets the right data", function() {
expect(scope.jobs[0]).toBeSimilarTo(myJob);
});
Of course, it's a very simple matcher and doesn't support many cases, but I didn't need anything more complex than that. You can wrap the matchers in a config file.
Check this answer for a similar implementation.