Last active
December 17, 2015 02:18
-
-
Save darsen/5534289 to your computer and use it in GitHub Desktop.
Using Jasmine and custom matchers to check object equality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Money(amount, currency){ | |
this.amount = amount; | |
this.currency = currency; | |
this.sum = function (money){ | |
return new Money(200, "CLP"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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