This breaks each call out onto its own line, so that it's much easier to
see where each call starts and how they differ. E.g. previously the output
would be:
Expected spy foo to have been called with [ 'bar', 'baz', 'qux' ] but actual calls were [ [ 42, 'wibble' ], [ 'bar' 'qux' ], [ 'grault '] ]
Now it's:
Expected spy foo to have been called with:
[ 'bar', 'baz', 'qux' ]
but actual calls were:
[ 42, 'wibble' ],
[ 'bar' 'qux' ],
[ 'grault '].
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
describe("toHaveBeenCalledWith", function() {
|
|
|
|
it("passes when the actual was called with matching parameters", function() {
|
|
var util = {
|
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
|
},
|
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
|
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
|
result;
|
|
|
|
calledSpy('a', 'b');
|
|
result = matcher.compare(calledSpy, 'a', 'b');
|
|
|
|
expect(result.pass).toBe(true);
|
|
expect(result.message()).toEqual("Expected spy called-spy not to have been called with:\n [ 'a', 'b' ]\nbut 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 = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
|
calledSpy = new jasmineUnderTest.Env().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() {
|
|
var util = {
|
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
|
},
|
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
|
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
|
result;
|
|
|
|
result = matcher.compare(uncalledSpy);
|
|
expect(result.pass).toBe(false);
|
|
expect(result.message()).toEqual("Expected spy uncalled spy to have been called with:\n [ ]\nbut it was never called.");
|
|
});
|
|
|
|
it("fails when the actual was called with different parameters", function() {
|
|
var util = {
|
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
|
},
|
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
|
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'),
|
|
result;
|
|
|
|
calledSpy('a');
|
|
calledSpy('c', 'd');
|
|
result = matcher.compare(calledSpy, 'a', 'b');
|
|
|
|
expect(result.pass).toBe(false);
|
|
expect(result.message()).toEqual("Expected spy called spy to have been called with:\n [ 'a', 'b' ]\nbut actual calls were:\n [ 'a' ],\n [ 'c', 'd' ].");
|
|
});
|
|
|
|
it("throws an exception when the actual is not a spy", function() {
|
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(),
|
|
fn = function() {};
|
|
|
|
expect(function() { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
|
|
});
|
|
});
|