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

@@ -1,44 +1,44 @@
describe("toHaveBeenCalled", function() {
it("passes when the actual was called, with a custom .not fail message", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(),
var matcher = j$.matchers.toHaveBeenCalled(),
calledSpy = j$.createSpy('called-spy'),
result;
calledSpy();
result = matcherComparator(calledSpy);
result = matcher.compare(calledSpy);
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected spy called-spy not to have been called.");
});
it("fails when the actual was not called", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(),
var matcher = j$.matchers.toHaveBeenCalled(),
uncalledSpy = j$.createSpy('uncalled spy');
result = matcherComparator(uncalledSpy);
result = matcher.compare(uncalledSpy);
expect(result.pass).toBe(false);
});
it("throws an exception when the actual is not a spy", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(),
var matcher = j$.matchers.toHaveBeenCalled(),
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."));
});
it("throws an exception when invoked with any arguments", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(),
var matcher = j$.matchers.toHaveBeenCalled(),
spy = j$.createSpy('sample spy');
expect(function() { matcherComparator(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith"));
expect(function() { matcher.compare(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith"));
});
it("has a custom message on failure", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(),
var matcher = j$.matchers.toHaveBeenCalled(),
spy = j$.createSpy('sample-spy'),
result;
result = matcherComparator(spy);
result = matcher.compare(spy);
expect(result.message).toEqual("Expected spy sample-spy to have been called.");
});