Updated toHaveBeenCalledOnceWith for new matcher interface
This commit is contained in:
@@ -5816,7 +5816,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
* @example
|
* @example
|
||||||
* expect(mySpy).toHaveBeenCalledOnceWith('foo', 'bar', 2);
|
* expect(mySpy).toHaveBeenCalledOnceWith('foo', 'bar', 2);
|
||||||
*/
|
*/
|
||||||
function toHaveBeenCalledOnceWith(util, customEqualityTesters) {
|
function toHaveBeenCalledOnceWith(util) {
|
||||||
return {
|
return {
|
||||||
compare: function () {
|
compare: function () {
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
var args = Array.prototype.slice.call(arguments, 0),
|
||||||
@@ -5831,7 +5831,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
return ' ' + j$.pp(argsForCall);
|
return ' ' + j$.pp(argsForCall);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (actual.calls.count() === 1 && util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
if (actual.calls.count() === 1 && util.contains(actual.calls.allArgs(), expectedArgs)) {
|
||||||
return {
|
return {
|
||||||
pass: true,
|
pass: true,
|
||||||
message: 'Expected spy ' + actual.and.identity + ' to have been called 0 times, multiple times, or once, but with arguments different from:\n'
|
message: 'Expected spy ' + actual.and.identity + ' to have been called 0 times, multiple times, or once, but with arguments different from:\n'
|
||||||
@@ -5844,7 +5844,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
function getDiffs() {
|
function getDiffs() {
|
||||||
return actual.calls.allArgs().map(function (argsForCall, callIx) {
|
return actual.calls.allArgs().map(function (argsForCall, callIx) {
|
||||||
var diffBuilder = new j$.DiffBuilder();
|
var diffBuilder = new j$.DiffBuilder();
|
||||||
util.equals(argsForCall, expectedArgs, customEqualityTesters, diffBuilder);
|
util.equals(argsForCall, expectedArgs, diffBuilder);
|
||||||
return diffBuilder.getMessage();
|
return diffBuilder.getMessage();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,18 +13,17 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
expect(result.message).toEqual("Expected spy called-spy to have been called 0 times, multiple times, or once, but with arguments different from:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'b' ].\n\n");
|
expect(result.message).toEqual("Expected spy called-spy to have been called 0 times, multiple times, or once, but with arguments different from:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'b' ].\n\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes through the custom equality testers", function () {
|
it("supports custom equality testers", function () {
|
||||||
var util = jasmineUnderTest.matchersUtil;
|
var customEqualityTesters = [function() { return true; }],
|
||||||
spyOn(util, 'contains').and.returnValue(false);
|
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(matchersUtil),
|
||||||
var customEqualityTesters = [function () { return true; }],
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util, customEqualityTesters),
|
result;
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy');
|
|
||||||
|
|
||||||
calledSpy('a', 'b');
|
calledSpy('a', 'b');
|
||||||
matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'a');
|
||||||
|
|
||||||
expect(util.contains).toHaveBeenCalledWith([['a', 'b']], ['a', 'b'], customEqualityTesters);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was never called", function () {
|
it("fails when the actual was never called", function () {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
* @example
|
* @example
|
||||||
* expect(mySpy).toHaveBeenCalledOnceWith('foo', 'bar', 2);
|
* expect(mySpy).toHaveBeenCalledOnceWith('foo', 'bar', 2);
|
||||||
*/
|
*/
|
||||||
function toHaveBeenCalledOnceWith(util, customEqualityTesters) {
|
function toHaveBeenCalledOnceWith(util) {
|
||||||
return {
|
return {
|
||||||
compare: function () {
|
compare: function () {
|
||||||
var args = Array.prototype.slice.call(arguments, 0),
|
var args = Array.prototype.slice.call(arguments, 0),
|
||||||
@@ -26,7 +26,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
return ' ' + j$.pp(argsForCall);
|
return ' ' + j$.pp(argsForCall);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (actual.calls.count() === 1 && util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
if (actual.calls.count() === 1 && util.contains(actual.calls.allArgs(), expectedArgs)) {
|
||||||
return {
|
return {
|
||||||
pass: true,
|
pass: true,
|
||||||
message: 'Expected spy ' + actual.and.identity + ' to have been called 0 times, multiple times, or once, but with arguments different from:\n'
|
message: 'Expected spy ' + actual.and.identity + ' to have been called 0 times, multiple times, or once, but with arguments different from:\n'
|
||||||
@@ -39,7 +39,7 @@ getJasmineRequireObj().toHaveBeenCalledOnceWith = function (j$) {
|
|||||||
function getDiffs() {
|
function getDiffs() {
|
||||||
return actual.calls.allArgs().map(function (argsForCall, callIx) {
|
return actual.calls.allArgs().map(function (argsForCall, callIx) {
|
||||||
var diffBuilder = new j$.DiffBuilder();
|
var diffBuilder = new j$.DiffBuilder();
|
||||||
util.equals(argsForCall, expectedArgs, customEqualityTesters, diffBuilder);
|
util.equals(argsForCall, expectedArgs, diffBuilder);
|
||||||
return diffBuilder.getMessage();
|
return diffBuilder.getMessage();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user