Merge branch 'pimterry-trackReturnValues'

This commit is contained in:
slackersoft
2014-09-22 13:04:18 -07:00
4 changed files with 37 additions and 8 deletions

View File

@@ -154,11 +154,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
}),
callTracker = new j$.CallTracker(),
spy = function() {
callTracker.track({
var callData = {
object: this,
args: Array.prototype.slice.apply(arguments)
});
return spyStrategy.exec.apply(this, arguments);
};
callTracker.track(callData);
var returnValue = spyStrategy.exec.apply(this, arguments);
callData.returnValue = returnValue;
return returnValue;
};
for (var prop in originalFn) {

View File

@@ -47,6 +47,16 @@ describe('Spies', function () {
expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
});
it("tracks the return value of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
spy.and.returnValue("return value");
spy();
expect(trackSpy.calls.mostRecent().args[0].returnValue).toEqual("return value");
});
});
describe("createSpyObj", function() {

View File

@@ -205,9 +205,14 @@ describe("Env integration", function() {
var env = new j$.Env();
var originalFunctionWasCalled = false;
var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
var subject = {
spiedFunc: function() {
originalFunctionWasCalled = true;
return "original result";
}
};
var spy = env.spyOn(subject, 'spiedFunc');
var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result");
expect(subject.spiedFunc).toEqual(spy);
@@ -220,11 +225,15 @@ describe("Env integration", function() {
expect(subject.spiedFunc.calls.count()).toEqual(1);
expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("stubbed result");
expect(originalFunctionWasCalled).toEqual(false);
subject.spiedFunc.and.callThrough();
subject.spiedFunc('bar');
expect(subject.spiedFunc.calls.count()).toEqual(2);
expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("original result");
expect(originalFunctionWasCalled).toEqual(true);
});
it("Mock clock can be installed and used in tests", function(done) {

View File

@@ -54,11 +54,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
}),
callTracker = new j$.CallTracker(),
spy = function() {
callTracker.track({
var callData = {
object: this,
args: Array.prototype.slice.apply(arguments)
});
return spyStrategy.exec.apply(this, arguments);
};
callTracker.track(callData);
var returnValue = spyStrategy.exec.apply(this, arguments);
callData.returnValue = returnValue;
return returnValue;
};
for (var prop in originalFn) {