-
-
Save bbraithwaite/376bb62af8b003b94fdc to your computer and use it in GitHub Desktop.
This file contains 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
var calculator = { | |
sum: function (x, y) { | |
return x + y; | |
}, | |
subtract: function (x, y) { | |
return x - y; | |
}, | |
divide: function (x, y) { | |
return (y === 0) ? 0 : x / y; | |
} | |
} | |
describe('calculator', function () { | |
describe('sum', function () { | |
it('1 + 1 should equal 2', function () { | |
expect(calculator.sum(1, 1)).toBe(2); | |
}); | |
}); | |
describe('subtract', function () { | |
it('3 - 2 should equal 1', function () { | |
expect(calculator.subtract(3, 2)).toBe(1); | |
}); | |
}); | |
describe('divide', function () { | |
it('10 / 5 should equal 2', function () { | |
expect(calculator.divide(10, 5)).toBe(2); | |
}); | |
it('zero divisor should equal 0', function () { | |
expect(calculator.divide(10, 0)).toBe(0); | |
}); | |
}); | |
}); |
nicely explained ...!
thank you 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could someone tell me how to test this block? In typescript and angular 2. In short, I would like to know how to access and set a function's local variables like in this case.