mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-01-30 21:47:35 +00:00
Improved jasmine SpyObj type
Only object methods will be merged with a Spy
This commit is contained in:
parent
f25ce87763
commit
d89ab9a678
5
types/jasmine/index.d.ts
vendored
5
types/jasmine/index.d.ts
vendored
@ -9,6 +9,7 @@
|
||||
// Chris Yungmann <https://github.com/cyungmann>
|
||||
// Giles Roadnight <https://github.com/Roaders>
|
||||
// Yaroslav Admin <https://github.com/devoto13>
|
||||
// Domas Trijonis <https://github.com/fdim>
|
||||
// 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> = T & {
|
||||
[k in keyof T]: Spy;
|
||||
type SpyObj<T> = {
|
||||
[k in keyof T]: T[k] extends Function ? T[k] & Spy : T[k];
|
||||
}
|
||||
|
||||
interface SpyAnd {
|
||||
|
||||
@ -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<Tape>;
|
||||
var el: jasmine.SpyObj<Element>;
|
||||
|
||||
beforeEach(() => {
|
||||
tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']);
|
||||
tape = jasmine.createSpyObj<Tape>('tape', ['play', 'pause', 'stop', 'rewind']);
|
||||
(tape as { isPlaying: boolean }).isPlaying = false;
|
||||
el = jasmine.createSpyObj<Element>('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", () => {
|
||||
|
||||
5
types/jasmine/v2/index.d.ts
vendored
5
types/jasmine/v2/index.d.ts
vendored
@ -8,6 +8,7 @@
|
||||
// Boris Breuer <https://github.com/Engineer2B>
|
||||
// Chris Yungmann <https://github.com/cyungmann>
|
||||
// Yaroslav Admin <https://github.com/devoto13>
|
||||
// Domas Trijonis <https://github.com/fdim>
|
||||
// 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> = T & {
|
||||
[k in keyof T]: Spy;
|
||||
type SpyObj<T> = {
|
||||
[k in keyof T]: T[k] extends Function ? T[k] & Spy : T[k];
|
||||
}
|
||||
|
||||
interface SpyAnd {
|
||||
|
||||
@ -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<Tape>;
|
||||
var el: jasmine.SpyObj<Element>;
|
||||
|
||||
beforeEach(() => {
|
||||
tape = jasmine.createSpyObj('tape', ['play', 'pause', 'stop', 'rewind']);
|
||||
tape = jasmine.createSpyObj<Tape>('tape', ['play', 'pause', 'stop', 'rewind']);
|
||||
(tape as { isPlaying: boolean }).isPlaying = false;
|
||||
el = jasmine.createSpyObj<Element>('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", () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user