Skip to content

Instantly share code, notes, and snippets.

@darsen
Last active December 17, 2015 02:18
Show Gist options
  • Save darsen/5534289 to your computer and use it in GitHub Desktop.
Save darsen/5534289 to your computer and use it in GitHub Desktop.
Using Jasmine and custom matchers to check object equality.
function Money(amount, currency){
this.amount = amount;
this.currency = currency;
this.sum = function (money){
return new Money(200, "CLP");
}
}
beforeEach(function() {
this.addMatchers({
toEqualMoney: function(expected) {
if(this.actual.amount == expected.amount &&
this.actual.currency == expected.currency){
return true;
}
return false
}
});
});
describe("Given 100 CLP", function(){
var CLP100 = new Money(100, "CLP");
it("should return 200 CLP when 100 CLP added ", function() {
var result = CLP100.sum(CLP100);
var expected = new Money(200, "CLP");
expect(result).toEqualMoney(expected);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment