mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
Merge pull request #31979 from FDIM/bugfix/spy-obj-and-T-union
[@types/jasmine] SpyObj and T union
This commit is contained in:
Vendored
+1
-1
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Vendored
+1
-1
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user