Allow omitting the name argument: createSpy(func)

This commit is contained in:
Fangzhou Li
2018-04-29 06:02:43 +08:00
parent 7e14a97371
commit fbcdbf5ab1
2 changed files with 12 additions and 0 deletions

View File

@@ -20,6 +20,13 @@ describe('Spies', function () {
expect(spy.bob).toEqual("test");
});
it("should allow you to omit the name argument and only pass the originalFn argument", function() {
var fn = function test() {};
var spy = env.createSpy(fn);
expect(spy.and.identity).toEqual("test");
})
it("warns the user that we intend to overwrite an existing property", function() {
TestClass.prototype.someFunction.and = "turkey";

View File

@@ -474,6 +474,11 @@ getJasmineRequireObj().Env = function(j$) {
};
this.createSpy = function(name, originalFn) {
if (arguments.length === 1 && j$.isFunction_(name)) {
originalFn = name;
name = originalFn.name;
}
return spyFactory.createSpy(name, originalFn);
};