Skip to content

Commit fbcdbf5

Browse files
committed
Allow omitting the name argument: createSpy(func)
1 parent 7e14a97 commit fbcdbf5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

spec/core/SpySpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ describe('Spies', function () {
2020
expect(spy.bob).toEqual("test");
2121
});
2222

23+
it("should allow you to omit the name argument and only pass the originalFn argument", function() {
24+
var fn = function test() {};
25+
var spy = env.createSpy(fn);
26+
27+
expect(spy.and.identity).toEqual("test");
28+
})
29+
2330
it("warns the user that we intend to overwrite an existing property", function() {
2431
TestClass.prototype.someFunction.and = "turkey";
2532

src/core/Env.js

+5
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ getJasmineRequireObj().Env = function(j$) {
474474
};
475475

476476
this.createSpy = function(name, originalFn) {
477+
if (arguments.length === 1 && j$.isFunction_(name)) {
478+
originalFn = name;
479+
name = originalFn.name;
480+
}
481+
477482
return spyFactory.createSpy(name, originalFn);
478483
};
479484

0 commit comments

Comments
 (0)