Pass through custom equality testers in toHaveBeenCalledWith [fixes #536]
This commit is contained in:
@@ -2257,7 +2257,7 @@ getJasmineRequireObj().toHaveBeenCalled = function(j$) {
|
|||||||
|
|
||||||
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
||||||
|
|
||||||
function toHaveBeenCalledWith(util) {
|
function toHaveBeenCalledWith(util, customEqualityTesters) {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
var args = Array.prototype.slice.call(arguments, 0),
|
||||||
@@ -2274,7 +2274,7 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (util.contains(actual.calls.allArgs(), expectedArgs)) {
|
if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
||||||
result.pass = true;
|
result.pass = true;
|
||||||
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -14,6 +14,20 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
expect(result.message()).toEqual("Expected spy called-spy not to have been called with [ 'a', 'b' ] but it was.");
|
expect(result.message()).toEqual("Expected spy called-spy not to have been called with [ 'a', 'b' ] but it was.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("passes through the custom equality testers", function() {
|
||||||
|
var util = {
|
||||||
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||||
|
},
|
||||||
|
customEqualityTesters = [function() { return true; }],
|
||||||
|
matcher = j$.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
||||||
|
calledSpy = j$.createSpy('called-spy');
|
||||||
|
|
||||||
|
calledSpy('a', 'b');
|
||||||
|
matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
|
expect(util.contains).toHaveBeenCalledWith([['a', 'b']], ['a', 'b'], customEqualityTesters);
|
||||||
|
});
|
||||||
|
|
||||||
it("fails when the actual was not called", function() {
|
it("fails when the actual was not called", function() {
|
||||||
var util = {
|
var util = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
||||||
|
|
||||||
function toHaveBeenCalledWith(util) {
|
function toHaveBeenCalledWith(util, customEqualityTesters) {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
var args = Array.prototype.slice.call(arguments, 0),
|
||||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (util.contains(actual.calls.allArgs(), expectedArgs)) {
|
if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
||||||
result.pass = true;
|
result.pass = true;
|
||||||
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user