Merge branch 'logankd-master'

- Support call count of 0 with toHaveBeenCalledTimes matcher

- Merges #1048
- Fixes #994
This commit is contained in:
Gregg Van Hove
2016-02-17 10:29:01 -08:00
3 changed files with 13 additions and 9 deletions

View File

@@ -3138,8 +3138,8 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
var args = Array.prototype.slice.call(arguments, 0), var args = Array.prototype.slice.call(arguments, 0),
result = { pass: false }; result = { pass: false };
if(!expected){ if (!j$.isNumber_(expected)){
throw new Error('Expected times failed is required as an argument.'); throw new Error('The expected times failed is a required argument and must be a number.');
} }
actual = args[0]; actual = args[0];
@@ -3156,7 +3156,6 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
return toHaveBeenCalledTimes; return toHaveBeenCalledTimes;
}; };
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
function toHaveBeenCalledWith(util, customEqualityTesters) { function toHaveBeenCalledWith(util, customEqualityTesters) {

View File

@@ -1,4 +1,11 @@
describe("toHaveBeenCalledTimes", function() { describe("toHaveBeenCalledTimes", function() {
it("passes when the actual 0 matches the expected 0 ", function () {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
calledSpy = jasmineUnderTest.createSpy('called-spy'),
result;
result = matcher.compare(calledSpy, 0);
expect(result.pass).toBeTruthy();
});
it("passes when the actual matches the expected", function() { it("passes when the actual matches the expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
calledSpy = jasmineUnderTest.createSpy('called-spy'), calledSpy = jasmineUnderTest.createSpy('called-spy'),
@@ -17,7 +24,7 @@ describe("toHaveBeenCalledTimes", function() {
spy(); spy();
expect(function() { expect(function() {
matcher.compare(spy); matcher.compare(spy);
}).toThrowError('Expected times failed is required as an argument.'); }).toThrowError('The expected times failed is a required argument and must be a number.');
}); });
it("fails when the actual was called less than the expected", function() { it("fails when the actual was called less than the expected", function() {
@@ -60,7 +67,6 @@ describe("toHaveBeenCalledTimes", function() {
spy(); spy();
result = matcher.compare(spy, 1); result = matcher.compare(spy, 1);
expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.'); expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.');
}); });
@@ -74,7 +80,6 @@ describe("toHaveBeenCalledTimes", function() {
spy(); spy();
result = matcher.compare(spy, 2); result = matcher.compare(spy, 2);
expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.'); expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.');
}); });
}); });

View File

@@ -10,8 +10,8 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
var args = Array.prototype.slice.call(arguments, 0), var args = Array.prototype.slice.call(arguments, 0),
result = { pass: false }; result = { pass: false };
if(!expected){ if (!j$.isNumber_(expected)){
throw new Error('Expected times failed is required as an argument.'); throw new Error('The expected times failed is a required argument and must be a number.');
} }
actual = args[0]; actual = args[0];