From d8afe0d544aabd0f2644a2a94615594189fdc4c1 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 16 Jan 2019 14:28:46 +0100 Subject: [PATCH 1/3] jasmine: add type for async ImplementationCallback --- types/jasmine/index.d.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index 2109645eef..afd9a943e8 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -15,6 +15,8 @@ // TypeScript Version: 2.8 // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts +type ImplementationCallback = (() => Promise) | ((done: DoneFn) => void); + /** * Create a group of specs (often called a suite). * @param description Textual description of the group @@ -31,7 +33,7 @@ declare function xdescribe(description: string, specDefinitions: () => void): vo * @param assertion Function that contains the code of your test. If not provided the test will be pending. * @param timeout Custom timeout for an async spec. */ -declare function it(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; +declare function it(expectation: string, assertion?: ImplementationCallback, timeout?: number): void; /** * A focused it @@ -40,8 +42,8 @@ declare function it(expectation: string, assertion?: (done: DoneFn) => void, tim * @param assertion * @param timeout */ -declare function fit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; -declare function xit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; +declare function fit(expectation: string, assertion?: ImplementationCallback, timeout?: number): void; +declare function xit(expectation: string, assertion?: ImplementationCallback, timeout?: number): void; /** * Mark a spec as pending, expectation results will be ignored. @@ -56,14 +58,14 @@ declare function pending(reason?: string): void; * @param action Function that contains the code to setup your specs. * @param timeout Custom timeout for an async beforeEach. */ -declare function beforeEach(action: (done: DoneFn) => void, timeout?: number): void; +declare function beforeEach(action: ImplementationCallback, timeout?: number): void; /** * Run some shared teardown after each of the specs in the describe in which it is called. * @param action Function that contains the code to teardown your specs. * @param timeout Custom timeout for an async afterEach. */ -declare function afterEach(action: (done: DoneFn) => void, timeout?: number): void; +declare function afterEach(action: ImplementationCallback, timeout?: number): void; /** * Run some shared setup once before all of the specs in the describe are run. @@ -71,7 +73,7 @@ declare function afterEach(action: (done: DoneFn) => void, timeout?: number): vo * @param action Function that contains the code to setup your specs. * @param timeout Custom timeout for an async beforeAll. */ -declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): void; +declare function beforeAll(action: ImplementationCallback, timeout?: number): void; /** * Run some shared teardown once before all of the specs in the describe are run. @@ -79,7 +81,7 @@ declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): vo * @param action Function that contains the code to teardown your specs. * @param timeout Custom timeout for an async afterAll */ -declare function afterAll(action: (done: DoneFn) => void, timeout?: number): void; +declare function afterAll(action: ImplementationCallback, timeout?: number): void; /** * Create an expectation for a spec. @@ -289,11 +291,11 @@ declare namespace jasmine { execute(): void; describe(description: string, specDefinitions: () => void): Suite; // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these - beforeEach(beforeEachFunction: (done: DoneFn) => void, timeout?: number): void; - beforeAll(beforeAllFunction: (done: DoneFn) => void, timeout?: number): void; + beforeEach(beforeEachFunction: ImplementationCallback, timeout?: number): void; + beforeAll(beforeAllFunction: ImplementationCallback, timeout?: number): void; currentRunner(): Runner; - afterEach(afterEachFunction: (done: DoneFn) => void, timeout?: number): void; - afterAll(afterAllFunction: (done: DoneFn) => void, timeout?: number): void; + afterEach(afterEachFunction: ImplementationCallback, timeout?: number): void; + afterAll(afterAllFunction: ImplementationCallback, timeout?: number): void; xdescribe(desc: string, specDefinitions: () => void): XSuite; it(description: string, func: () => void): Spec; // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these From d51f58741daa646b4e54bc10f65ae47263686872 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 16 Jan 2019 15:37:07 +0100 Subject: [PATCH 2/3] change v2 as well --- types/jasmine/v2/index.d.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/types/jasmine/v2/index.d.ts b/types/jasmine/v2/index.d.ts index 4211cf2ca0..dc0bc6606f 100644 --- a/types/jasmine/v2/index.d.ts +++ b/types/jasmine/v2/index.d.ts @@ -13,6 +13,8 @@ // TypeScript Version: 2.8 // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts +type ImplementationCallback = (() => Promise) | ((done: DoneFn) => void); + /** * Create a group of specs (often called a suite). * @param description Textual description of the group @@ -29,7 +31,7 @@ declare function xdescribe(description: string, specDefinitions: () => void): vo * @param assertion Function that contains the code of your test. If not provided the test will be pending. * @param timeout Custom timeout for an async spec. */ -declare function it(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; +declare function it(expectation: string, assertion?: ImplementationCallback, timeout?: number): void; /** * A focused it @@ -38,8 +40,8 @@ declare function it(expectation: string, assertion?: (done: DoneFn) => void, tim * @param assertion * @param timeout */ -declare function fit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; -declare function xit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; +declare function fit(expectation: string, assertion?: ImplementationCallback, timeout?: number): void; +declare function xit(expectation: string, assertion?: ImplementationCallback, timeout?: number): void; /** * Mark a spec as pending, expectation results will be ignored. @@ -54,14 +56,14 @@ declare function pending(reason?: string): void; * @param action Function that contains the code to setup your specs. * @param timeout Custom timeout for an async beforeEach. */ -declare function beforeEach(action: (done: DoneFn) => void, timeout?: number): void; +declare function beforeEach(action: ImplementationCallback, timeout?: number): void; /** * Run some shared teardown after each of the specs in the describe in which it is called. * @param action Function that contains the code to teardown your specs. * @param timeout Custom timeout for an async afterEach. */ -declare function afterEach(action: (done: DoneFn) => void, timeout?: number): void; +declare function afterEach(action: ImplementationCallback, timeout?: number): void; /** * Run some shared setup once before all of the specs in the describe are run. @@ -69,7 +71,7 @@ declare function afterEach(action: (done: DoneFn) => void, timeout?: number): vo * @param action Function that contains the code to setup your specs. * @param timeout Custom timeout for an async beforeAll. */ -declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): void; +declare function beforeAll(action: ImplementationCallback, timeout?: number): void; /** * Run some shared teardown once before all of the specs in the describe are run. @@ -77,7 +79,7 @@ declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): vo * @param action Function that contains the code to teardown your specs. * @param timeout Custom timeout for an async afterAll */ -declare function afterAll(action: (done: DoneFn) => void, timeout?: number): void; +declare function afterAll(action: ImplementationCallback, timeout?: number): void; /** * Create an expectation for a spec. @@ -268,11 +270,11 @@ declare namespace jasmine { execute(): void; describe(description: string, specDefinitions: () => void): Suite; // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these - beforeEach(beforeEachFunction: (done: DoneFn) => void, timeout?: number): void; - beforeAll(beforeAllFunction: (done: DoneFn) => void, timeout?: number): void; + beforeEach(beforeEachFunction: ImplementationCallback, timeout?: number): void; + beforeAll(beforeAllFunction: ImplementationCallback, timeout?: number): void; currentRunner(): Runner; - afterEach(afterEachFunction: (done: DoneFn) => void, timeout?: number): void; - afterAll(afterAllFunction: (done: DoneFn) => void, timeout?: number): void; + afterEach(afterEachFunction: ImplementationCallback, timeout?: number): void; + afterAll(afterAllFunction: ImplementationCallback, timeout?: number): void; xdescribe(desc: string, specDefinitions: () => void): XSuite; it(description: string, func: () => void): Spec; // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these From e1d8dcb4f6a9efe0bd79a4afa9b76d9b4758b67e Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Fri, 18 Jan 2019 23:30:01 +0100 Subject: [PATCH 3/3] fix lint --- types/jasmine/jasmine-tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 47cc77895c..66b98c4b0d 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -725,12 +725,12 @@ describe("A spy, when created manually", () => { describe("Multiple spies, when created manually", () => { class Tape { private rewindTo: number; - play(): void { }; - pause(): void { }; + play(): void { } + pause(): void { } rewind(pos: number): void { this.rewindTo = pos; - }; - stop(): void { }; + } + stop(): void { } readonly isPlaying: boolean; // spy obj makes this writable }