From 5c182b9af717f73146399c2485f70f1e2ac0ff2b Mon Sep 17 00:00:00 2001 From: mmmichl Date: Tue, 12 Apr 2016 15:44:38 +0200 Subject: [PATCH] Introduce done function declaration with fail method (#8891) --- jasmine/jasmine-tests.ts | 10 +++++----- jasmine/jasmine.d.ts | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index 81f1a1a88..45b2d155a 100644 --- a/jasmine/jasmine-tests.ts +++ b/jasmine/jasmine-tests.ts @@ -747,31 +747,31 @@ describe("Manually ticking the Jasmine Clock", function () { describe("Asynchronous specs", function () { var value: number; - beforeEach(function (done) { + beforeEach(function (done: DoneFn) { setTimeout(function () { value = 0; done(); }, 1); }); - it("should support async execution of test preparation and expectations", function (done) { + it("should support async execution of test preparation and expectations", function (done: DoneFn) { value++; expect(value).toBeGreaterThan(0); done(); }); describe("long asynchronous specs", function() { - beforeEach(function(done) { + beforeEach(function(done: DoneFn) { done(); }, 1000); - it("takes a long time", function(done) { + it("takes a long time", function(done: DoneFn) { setTimeout(function() { done(); }, 9000); }, 10000); - afterEach(function(done) { + afterEach(function(done: DoneFn) { done(); }, 1000); }); diff --git a/jasmine/jasmine.d.ts b/jasmine/jasmine.d.ts index 4fa5a7ade..aa3acdfbf 100644 --- a/jasmine/jasmine.d.ts +++ b/jasmine/jasmine.d.ts @@ -11,29 +11,36 @@ declare function fdescribe(description: string, specDefinitions: () => void): vo declare function xdescribe(description: string, specDefinitions: () => void): void; declare function it(expectation: string, assertion?: () => void, timeout?: number): void; -declare function it(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; +declare function it(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; declare function fit(expectation: string, assertion?: () => void, timeout?: number): void; -declare function fit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; +declare function fit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; declare function xit(expectation: string, assertion?: () => void, timeout?: number): void; -declare function xit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; +declare function xit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void; /** If you call the function pending anywhere in the spec body, no matter the expectations, the spec will be marked pending. */ declare function pending(reason?: string): void; declare function beforeEach(action: () => void, timeout?: number): void; -declare function beforeEach(action: (done: () => void) => void, timeout?: number): void; +declare function beforeEach(action: (done: DoneFn) => void, timeout?: number): void; declare function afterEach(action: () => void, timeout?: number): void; -declare function afterEach(action: (done: () => void) => void, timeout?: number): void; +declare function afterEach(action: (done: DoneFn) => void, timeout?: number): void; declare function beforeAll(action: () => void, timeout?: number): void; -declare function beforeAll(action: (done: () => void) => void, timeout?: number): void; +declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): void; declare function afterAll(action: () => void, timeout?: number): void; -declare function afterAll(action: (done: () => void) => void, timeout?: number): void; +declare function afterAll(action: (done: DoneFn) => void, timeout?: number): void; declare function expect(spy: Function): jasmine.Matchers; declare function expect(actual: any): jasmine.Matchers; declare function fail(e?: any): void; +/** Action method that should be called when the async work is complete */ +interface DoneFn extends Function { + (): void; + + /** fails the spec and indicates that it has completed. If the message is an Error, Error.message is used */ + fail: (message?: Error|string) => void; +} declare function spyOn(object: any, method: string): jasmine.Spy;