diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index f3e0407bab..cd1d5de31e 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -130,6 +130,7 @@ declare function waits(timeout?: number): void; declare namespace jasmine { type Expected = T | ObjectContaining | Any | Spy; + type SpyObjMethodNames = string[] | {[methodName: string]: any}; var clock: () => Clock; @@ -144,12 +145,11 @@ declare namespace jasmine { function objectContaining(sample: Partial): ObjectContaining; function createSpy(name?: string, originalFn?: Function): Spy; - function createSpyObj(baseName: string, methodNames: any[] | {[methodName: string]: any}): any; - function createSpyObj(baseName: string, methodNames: any[] | {[methodName: string]: any}): SpyObj; + function createSpyObj(baseName: string, methodNames: SpyObjMethodNames): any; + function createSpyObj(baseName: string, methodNames: SpyObjMethodNames): SpyObj; - function createSpyObj(baseName: string, methodNames: any): any; - function createSpyObj(methodNames: any[]): any; - function createSpyObj(methodNames: any): any; + function createSpyObj(methodNames: SpyObjMethodNames): any; + function createSpyObj(methodNames: SpyObjMethodNames): SpyObj; function pp(value: any): string; diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index b54269aa61..54e97ed73e 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -1109,7 +1109,17 @@ describe("createSpyObj", function () { expect(spyObj.method2.and.identity()).toEqual('BaseName.method2'); }); - it("should allow you to omit the baseName", function () { + it("should allow you to omit the baseName and takes only an object", function () { + var spyObj = jasmine.createSpyObj({ 'method1': 42, 'method2': 'special sauce' }); + + expect(spyObj.method1()).toEqual(42); + expect(spyObj.method1.and.identity()).toEqual('unknown.method1'); + + expect(spyObj.method2()).toEqual('special sauce'); + expect(spyObj.method2.and.identity()).toEqual('unknown.method2'); + }); + + it("should allow you to omit the baseName and takes only a list of methods", function () { var spyObj = jasmine.createSpyObj(['method1', 'method2']); expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function) }); @@ -1117,12 +1127,6 @@ describe("createSpyObj", function () { expect(spyObj.method2.and.identity()).toEqual('unknown.method2'); }); - it("should throw if you do not pass an array or object argument", function () { - expect(function () { - jasmine.createSpyObj('BaseName'); - }).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for"); - }); - it("should throw if you pass an empty array argument", function () { expect(function () { jasmine.createSpyObj('BaseName', []);