Make createSpyObj definitions consistent - same strict type for all methodNames arguments. (#25466)

This commit is contained in:
Md. Enzam Hossain
2018-05-03 09:07:04 -07:00
committed by Andy
parent 62da0e60ef
commit a1632b79b3
2 changed files with 16 additions and 12 deletions

View File

@@ -130,6 +130,7 @@ declare function waits(timeout?: number): void;
declare namespace jasmine {
type Expected<T> = T | ObjectContaining<T> | Any | Spy;
type SpyObjMethodNames = string[] | {[methodName: string]: any};
var clock: () => Clock;
@@ -144,12 +145,11 @@ declare namespace jasmine {
function objectContaining<T>(sample: Partial<T>): ObjectContaining<T>;
function createSpy(name?: string, originalFn?: Function): Spy;
function createSpyObj(baseName: string, methodNames: any[] | {[methodName: string]: any}): any;
function createSpyObj<T>(baseName: string, methodNames: any[] | {[methodName: string]: any}): SpyObj<T>;
function createSpyObj(baseName: string, methodNames: SpyObjMethodNames): any;
function createSpyObj<T>(baseName: string, methodNames: SpyObjMethodNames): SpyObj<T>;
function createSpyObj(baseName: string, methodNames: any): any;
function createSpyObj(methodNames: any[]): any;
function createSpyObj(methodNames: any): any;
function createSpyObj(methodNames: SpyObjMethodNames): any;
function createSpyObj<T>(methodNames: SpyObjMethodNames): SpyObj<T>;
function pp(value: any): string;

View File

@@ -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', []);