diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index b10db4645e..1a59399c1a 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -9,6 +9,7 @@ // Chris Yungmann // Giles Roadnight // Yaroslav Admin +// Domas Trijonis // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts @@ -643,8 +644,8 @@ declare namespace jasmine { withArgs(...args: any[]): Spy; } - type SpyObj = T & { - [k in keyof T]: Spy; + type SpyObj = { + [k in keyof T]: T[k] extends Function ? T[k] & Spy : T[k]; } interface SpyAnd { diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 31bdd5f46c..e4208b0b50 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -701,11 +701,20 @@ describe("A spy, when created manually", () => { }); describe("Multiple spies, when created manually", () => { - var tape: any; + interface Tape { + play(): void; + pause(): void; + rewind(pos: number): void; + stop(): void; + readonly isPlaying: boolean; // spy obj makes this writable + } + + var tape: jasmine.SpyObj; var el: jasmine.SpyObj; beforeEach(() => { - tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']); + tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']); + (tape as { isPlaying: boolean }).isPlaying = false; el = jasmine.createSpyObj('Element', ['hasAttribute']); el.hasAttribute.and.returnValue(false); @@ -733,6 +742,10 @@ describe("Multiple spies, when created manually", () => { it("tracks all the arguments of its calls", () => { expect(tape.rewind).toHaveBeenCalledWith(0); }); + + it("read isPlaying property", () => { + expect(tape.isPlaying).toBe(false); + }) }); describe("jasmine.nothing", () => { diff --git a/types/jasmine/v2/index.d.ts b/types/jasmine/v2/index.d.ts index 4a15b3d1da..4211cf2ca0 100644 --- a/types/jasmine/v2/index.d.ts +++ b/types/jasmine/v2/index.d.ts @@ -8,6 +8,7 @@ // Boris Breuer // Chris Yungmann // Yaroslav Admin +// Domas Trijonis // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts @@ -628,8 +629,8 @@ declare namespace jasmine { calls: Calls; } - type SpyObj = T & { - [k in keyof T]: Spy; + type SpyObj = { + [k in keyof T]: T[k] extends Function ? T[k] & Spy : T[k]; } interface SpyAnd { diff --git a/types/jasmine/v2/jasmine-tests.ts b/types/jasmine/v2/jasmine-tests.ts index fce7c59c9e..7ac8339a3e 100644 --- a/types/jasmine/v2/jasmine-tests.ts +++ b/types/jasmine/v2/jasmine-tests.ts @@ -643,11 +643,20 @@ describe("A spy, when created manually", () => { }); describe("Multiple spies, when created manually", () => { - var tape: any; + interface Tape { + play(): void; + pause(): void; + rewind(pos: number): void; + stop(): void; + readonly isPlaying: boolean; // spy obj makes this writable + } + + var tape: jasmine.SpyObj; var el: jasmine.SpyObj; beforeEach(() => { - tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']); + tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']); + (tape as { isPlaying: boolean }).isPlaying = false; el = jasmine.createSpyObj('Element', ['hasAttribute']); el.hasAttribute.and.returnValue(false); @@ -675,6 +684,10 @@ describe("Multiple spies, when created manually", () => { it("tracks all the arguments of its calls", () => { expect(tape.rewind).toHaveBeenCalledWith(0); }); + + it("read isPlaying property", () => { + expect(tape.isPlaying).toBe(false); + }) }); describe("jasmine.nothing", () => {