Revert removal of compare nesting

Since we want the user to be able to pass a negative comparison function, the extra layer of wrapping is now needed
This commit is contained in:
Kyriacos Souroullas and Sheel Choksi
2013-10-28 13:49:54 -07:00
parent dd8a455f91
commit e346e7dcc1
37 changed files with 493 additions and 435 deletions

View File

@@ -3,12 +3,12 @@ describe("toHaveBeenCalledWith", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
matcherComparator = j$.matchers.toHaveBeenCalledWith(util),
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called-spy'),
result;
calledSpy('a', 'b');
result = matcherComparator(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 [ 'a', 'b' ] but it was.");
@@ -18,11 +18,11 @@ describe("toHaveBeenCalledWith", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
},
matcherComparator = j$.matchers.toHaveBeenCalledWith(util),
matcher = j$.matchers.toHaveBeenCalledWith(util),
uncalledSpy = j$.createSpy('uncalled spy'),
result;
result = matcherComparator(uncalledSpy);
result = matcher.compare(uncalledSpy);
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy uncalled spy to have been called with [ ] but it was never called.");
});
@@ -31,22 +31,22 @@ describe("toHaveBeenCalledWith", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
},
matcherComparator = j$.matchers.toHaveBeenCalledWith(util),
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called spy'),
result;
calledSpy('a');
calledSpy('c', 'd');
result = matcherComparator(calledSpy, 'a', 'b');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called spy to have been called with [ 'a', 'b' ] but actual calls were [ 'a' ], [ 'c', 'd' ].");
});
it("throws an exception when the actual is not a spy", function() {
var matcherComparator = j$.matchers.toHaveBeenCalledWith(),
var matcher = j$.matchers.toHaveBeenCalledWith(),
fn = function() {};
expect(function() { matcherComparator(fn) }).toThrow(new Error("Expected a spy, but got Function."));
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
});
});