From 0e34512dd247d888beb8637782e84baf657a692e Mon Sep 17 00:00:00 2001 From: Petteri Parkkila Date: Fri, 31 Aug 2018 14:04:07 -0400 Subject: [PATCH] Reorder function overloads; * Overload with _function_ as an argument matches to overload with `Object` as an argument and thus the compiler never picks up function variant if it's ordered lower than `Object` one. --- types/supertest/index.d.ts | 3 ++- types/supertest/supertest-tests.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/types/supertest/index.d.ts b/types/supertest/index.d.ts index 092ab89bb4..77418352f9 100644 --- a/types/supertest/index.d.ts +++ b/types/supertest/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for SuperTest v2.0.1 // Project: https://github.com/visionmedia/supertest // Definitions by: Alex Varju +// Petteri Parkkila // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -23,12 +24,12 @@ declare namespace supertest { serverAddress(app: any, path: string): string; expect(status: number, callback?: CallbackHandler): this; expect(status: number, body: any, callback?: CallbackHandler): this; + expect(checker: (res: Response) => any): this; expect(body: string, callback?: CallbackHandler): this; expect(body: RegExp, callback?: CallbackHandler): this; expect(body: Object, callback?: CallbackHandler): this; expect(field: string, val: string, callback?: CallbackHandler): this; expect(field: string, val: RegExp, callback?: CallbackHandler): this; - expect(checker: (res: Response) => any): this; end(callback?: CallbackHandler): this; } diff --git a/types/supertest/supertest-tests.ts b/types/supertest/supertest-tests.ts index 24bbd4bd56..641b2bbabf 100644 --- a/types/supertest/supertest-tests.ts +++ b/types/supertest/supertest-tests.ts @@ -59,6 +59,17 @@ function hasPreviousAndNextKeys(res: supertest.Response) { if (!('prev' in res.body)) throw new Error("missing prev key"); } +// functional expect without response type +(request + .get('/') as supertest.Test) + .expect(res => { + if (!('next' in res.body)) return "missing next key"; + if (!('prev' in res.body)) throw new Error("missing prev key"); + }) + .end((err: any, res: supertest.Response) => { + if (err) throw err; + }); + // object expect (request .get('/') as supertest.Test)