From 5840cec935db7c25a4bc0b68cb37fb160bf28c20 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 17 Sep 2018 22:46:45 +0300 Subject: [PATCH] [jasminewd2] Add `DoneFn` to supporting functions `jasminewd2` [supports][1] Jasmine's passing a `DoneFn` callback to global `it`/`fit`/`xit`/`beforeAll`/`beforeEach`/`afterAll`/`afterEach` functions, but the types did not reflect that. (Related: Workaround in [angular/angular][2].) [1]: https://github.com/angular/jasminewd/blob/236b0d211ef7b8510629dcbc7d2a18afaabd2f10/index.js#L102-L118 [2]: https://github.com/angular/angular/blob/8f81dba367912d5c905dcd90893475e563bc2eea/tools/types-ext/jasminewd2.d.ts --- types/jasminewd2/index.d.ts | 15 +++++++------ types/jasminewd2/jasminewd2-tests.ts | 32 +++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/types/jasminewd2/index.d.ts b/types/jasminewd2/index.d.ts index d19b929fa7..66b5708aa5 100644 --- a/types/jasminewd2/index.d.ts +++ b/types/jasminewd2/index.d.ts @@ -1,18 +1,19 @@ // Type definitions for jasminewd2 2.0 // Project: https://github.com/angular/jasminewd // Definitions by: Sammy Jelin +// George Kalpakas // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 /// -declare function it(expectation: string, assertion?: () => Promise, timeout?: number): void; -declare function fit(expectation: string, assertion?: () => Promise, timeout?: number): void; -declare function xit(expectation: string, assertion?: () => Promise, timeout?: number): void; -declare function beforeEach(action: () => Promise, timeout?: number): void; -declare function afterEach(action: () => Promise, timeout?: number): void; -declare function beforeAll(action: () => Promise, timeout?: number): void; -declare function afterAll(action: () => Promise, timeout?: number): void; +declare function it(expectation: string, assertion?: (done: DoneFn) => Promise, timeout?: number): void; +declare function fit(expectation: string, assertion?: (done: DoneFn) => Promise, timeout?: number): void; +declare function xit(expectation: string, assertion?: (done: DoneFn) => Promise, timeout?: number): void; +declare function beforeEach(action: (done: DoneFn) => Promise, timeout?: number): void; +declare function afterEach(action: (done: DoneFn) => Promise, timeout?: number): void; +declare function beforeAll(action: (done: DoneFn) => Promise, timeout?: number): void; +declare function afterAll(action: (done: DoneFn) => Promise, timeout?: number): void; declare namespace jasmine { interface Matchers { diff --git a/types/jasminewd2/jasminewd2-tests.ts b/types/jasminewd2/jasminewd2-tests.ts index e201ed3cc0..aeb4540265 100644 --- a/types/jasminewd2/jasminewd2-tests.ts +++ b/types/jasminewd2/jasminewd2-tests.ts @@ -1,6 +1,4 @@ -let promise = new Promise((resolve, reject) => { - resolve(); -}); +const promise = Promise.resolve(); describe('jasminewd', () => { describe('global it, fit, xit, before and after', () => { @@ -31,6 +29,34 @@ describe('jasminewd', () => { afterAll(() => { return promise; }); + + it('should be able to use DoneFn', done => { + promise.then(done, done.fail); + }); + + fit('should be able to use DoneFn', done => { + promise.then(done, done.fail); + }); + + xit('should be able to use DoneFn', done => { + promise.then(done, done.fail); + }); + + beforeEach(done => { + promise.then(done, done.fail); + }); + + afterEach(done => { + promise.then(done, done.fail); + }); + + beforeAll(done => { + promise.then(done, done.fail); + }); + + afterAll(done => { + promise.then(done, done.fail); + }); }); describe('matchers', () => {