Merge pull request #31979 from FDIM/bugfix/spy-obj-and-T-union

[@types/jasmine] SpyObj and T union
This commit is contained in:
Ron Buckton
2019-01-17 22:05:04 -08:00
committed by GitHub
4 changed files with 35 additions and 17 deletions
+1 -1
View File
@@ -701,7 +701,7 @@ declare namespace jasmine {
withArgs(...args: any[]): Spy;
}
type SpyObj<T> = {
type SpyObj<T> = T & {
[k in keyof T]: T[k] extends Function ? T[k] & Spy : T[k];
}
+17 -8
View File
@@ -723,19 +723,24 @@ describe("A spy, when created manually", () => {
});
describe("Multiple spies, when created manually", () => {
interface Tape {
play(): void;
pause(): void;
rewind(pos: number): void;
stop(): void;
class Tape {
private rewindTo: number;
play(): void { };
pause(): void { };
rewind(pos: number): void {
this.rewindTo = pos;
};
stop(): void { };
readonly isPlaying: boolean; // spy obj makes this writable
}
var tape: jasmine.SpyObj<Tape>;
var tape: Tape;
var tapeSpy: jasmine.SpyObj<Tape>;
var el: jasmine.SpyObj<Element>;
beforeEach(() => {
tape = jasmine.createSpyObj<Tape>('tape', ['play', 'pause', 'stop', 'rewind']);
tapeSpy = jasmine.createSpyObj<Tape>('tape', ['play', 'pause', 'stop', 'rewind']);
tape = tapeSpy;
(tape as { isPlaying: boolean }).isPlaying = false;
el = jasmine.createSpyObj<Element>('Element', ['hasAttribute']);
@@ -745,6 +750,10 @@ describe("Multiple spies, when created manually", () => {
tape.play();
tape.pause();
tape.rewind(0);
tapeSpy.play.and.callThrough();
tapeSpy.pause.and.callThrough();
tapeSpy.rewind.and.callThrough();
});
it("creates spies for each requested function", () => {
@@ -767,7 +776,7 @@ describe("Multiple spies, when created manually", () => {
it("read isPlaying property", () => {
expect(tape.isPlaying).toBe(false);
})
});
});
describe("multiple spies, when created with spyOnAllFunctions", () => {
+1 -1
View File
@@ -629,7 +629,7 @@ declare namespace jasmine {
calls: Calls;
}
type SpyObj<T> = {
type SpyObj<T> = T & {
[k in keyof T]: T[k] extends Function ? T[k] & Spy : T[k];
}
+16 -7
View File
@@ -643,19 +643,24 @@ describe("A spy, when created manually", () => {
});
describe("Multiple spies, when created manually", () => {
interface Tape {
play(): void;
pause(): void;
rewind(pos: number): void;
stop(): void;
abstract class Tape {
private rewindTo: number;
play(): void { };
pause(): void { };
rewind(pos: number): void {
this.rewindTo = pos;
};
stop(): void { };
readonly isPlaying: boolean; // spy obj makes this writable
}
var tape: jasmine.SpyObj<Tape>;
var tape: Tape;
var tapeSpy: jasmine.SpyObj<Tape>;
var el: jasmine.SpyObj<Element>;
beforeEach(() => {
tape = jasmine.createSpyObj<Tape>('tape', ['play', 'pause', 'stop', 'rewind']);
tapeSpy = jasmine.createSpyObj<Tape>('tape', ['play', 'pause', 'stop', 'rewind']);
tape = tapeSpy;
(tape as { isPlaying: boolean }).isPlaying = false;
el = jasmine.createSpyObj<Element>('Element', ['hasAttribute']);
@@ -665,6 +670,10 @@ describe("Multiple spies, when created manually", () => {
tape.play();
tape.pause();
tape.rewind(0);
tapeSpy.play.and.callThrough();
tapeSpy.pause.and.callThrough();
tapeSpy.rewind.and.callThrough();
});
it("creates spies for each requested function", () => {