Mock callTracker in spy tests for better test isolation

This commit is contained in:
pimterry
2013-12-07 20:43:38 +00:00
parent 1d98a23b14
commit b2e8de7bcd

View File

@@ -31,16 +31,21 @@ describe('Spies', function () {
it("tracks the argument of calls", function () { it("tracks the argument of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction); var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
spy("arg"); spy("arg");
expect(spy.calls.mostRecent().args).toEqual(["arg"]);
expect(trackSpy.calls.mostRecent().args[0].args).toEqual(["arg"]);
}); });
it("tracks the context of calls", function () { it("tracks the context of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction); var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
var contextObject = { spyMethod: spy }; var contextObject = { spyMethod: spy };
contextObject.spyMethod(); contextObject.spyMethod();
expect(spy.calls[0].object).toEqual(contextObject); expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
}); });
}); });