mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Merge pull request #30975 from FDIM/task/improved-spy-obj-typing
[@types/jasmine] improvements to SpyObj type
This commit is contained in:
Vendored
+3
-2
@@ -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", () => {
|
||||
@@ -946,7 +959,7 @@ describe("Asynchronous specs", () => {
|
||||
});
|
||||
|
||||
it("should support async execution of test preparation and expectations", (done: DoneFn) => {
|
||||
value++;
|
||||
value += 1;
|
||||
expect(value).toBeGreaterThan(0);
|
||||
done();
|
||||
});
|
||||
@@ -1124,7 +1137,7 @@ var myReporter: jasmine.CustomReporter = {
|
||||
specDone: (result: jasmine.CustomReporterResult) => {
|
||||
console.log("Spec: " + result.description + " was " + result.status);
|
||||
//tslint:disable-next-line:prefer-for-of
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i++) {
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i += 1) {
|
||||
console.log("Failure: " + result.failedExpectations[i].message);
|
||||
console.log("Actual: " + result.failedExpectations[i].actual);
|
||||
console.log("Expected: " + result.failedExpectations[i].expected);
|
||||
@@ -1136,7 +1149,7 @@ var myReporter: jasmine.CustomReporter = {
|
||||
suiteDone: (result: jasmine.CustomReporterResult) => {
|
||||
console.log('Suite: ' + result.description + ' was ' + result.status);
|
||||
//tslint:disable-next-line:prefer-for-of
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i++) {
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i += 1) {
|
||||
console.log('AfterAll ' + result.failedExpectations[i].message);
|
||||
console.log(result.failedExpectations[i].stack);
|
||||
}
|
||||
|
||||
Vendored
+3
-2
@@ -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", () => {
|
||||
@@ -888,7 +901,7 @@ describe("Asynchronous specs", () => {
|
||||
});
|
||||
|
||||
it("should support async execution of test preparation and expectations", (done: DoneFn) => {
|
||||
value++;
|
||||
value += 1;
|
||||
expect(value).toBeGreaterThan(0);
|
||||
done();
|
||||
});
|
||||
@@ -1066,7 +1079,7 @@ var myReporter: jasmine.CustomReporter = {
|
||||
specDone: (result: jasmine.CustomReporterResult) => {
|
||||
console.log("Spec: " + result.description + " was " + result.status);
|
||||
//tslint:disable-next-line:prefer-for-of
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i++) {
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i += 1) {
|
||||
console.log("Failure: " + result.failedExpectations[i].message);
|
||||
console.log("Actual: " + result.failedExpectations[i].actual);
|
||||
console.log("Expected: " + result.failedExpectations[i].expected);
|
||||
@@ -1078,7 +1091,7 @@ var myReporter: jasmine.CustomReporter = {
|
||||
suiteDone: (result: jasmine.CustomReporterResult) => {
|
||||
console.log('Suite: ' + result.description + ' was ' + result.status);
|
||||
//tslint:disable-next-line:prefer-for-of
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i++) {
|
||||
for (var i = 0; result.failedExpectations && i < result.failedExpectations.length; i += 1) {
|
||||
console.log('AfterAll ' + result.failedExpectations[i].message);
|
||||
console.log(result.failedExpectations[i].stack);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user