diff --git a/supertest/index.d.ts b/supertest/index.d.ts index 36dc7a512e..f9c14e5d4b 100644 --- a/supertest/index.d.ts +++ b/supertest/index.d.ts @@ -7,7 +7,7 @@ import * as superagent from "superagent" export = supertest; -declare function supertest(app: any): supertest.SuperTest; +declare function supertest(app: any): supertest.SuperTest; declare namespace supertest { interface Response extends superagent.Response { } @@ -17,23 +17,23 @@ declare namespace supertest { type CallbackHandler = (err: any, res: Response) => void; interface Test extends Request { - app?: any; - url: string; - serverAddress(app: any, path: string): string; - expect(status: number, callback?: CallbackHandler): this; - expect(status: number, body: string, callback?: CallbackHandler): 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(fzield: string, val: RegExp, callback?: CallbackHandler): this; - expect(checker: (res: Response) => any): this; - end(callback?: CallbackHandler): this; + app?: any; + url: string; + serverAddress(app: any, path: string): string; + expect(status: number, callback?: CallbackHandler): this; + expect(status: number, body: any, callback?: CallbackHandler): 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(fzield: string, val: RegExp, callback?: CallbackHandler): this; + expect(checker: (res: Response) => any): this; + end(callback?: CallbackHandler): this; } function agent(app?: any): SuperTest; - interface SuperTest extends superagent.SuperAgent { + interface SuperTest extends superagent.SuperAgent { } } diff --git a/supertest/supertest-tests.ts b/supertest/supertest-tests.ts index 2e6c417f25..5be5558e46 100644 --- a/supertest/supertest-tests.ts +++ b/supertest/supertest-tests.ts @@ -2,27 +2,27 @@ import * as supertest from 'supertest'; import * as express from 'express'; -var app = express(); +const app = express(); supertest(app) .get('/user') .expect('Content-Type', /json/) .expect('Content-Length', '20') .expect(201) - .end((err: any, res: any) => { + .end((err, res) => { if (err) throw err; }); // cookie scenario -var request = supertest(app); -var agent = supertest.agent(); +const request = supertest(app); +const agent = supertest.agent(); request .post('/login') .end((err: any, res: supertest.Response) => { if (err) throw err; agent.saveCookies(res); - var req = request.get('/admin'); + const req = request.get('/admin'); agent.attachCookies(req); req.expect(200, (err: any, res: supertest.Response) => { if (err) throw err; @@ -30,7 +30,7 @@ request }); // cookie scenario, new version -var client = supertest.agent(app); +const client = supertest.agent(app); client .post('/login') .end((err: any, res: supertest.Response) => { @@ -54,3 +54,11 @@ function hasPreviousAndNextKeys(res: supertest.Response) { if (!('next' in res.body)) return "missing next key"; if (!('prev' in res.body)) throw new Error("missing prev key"); } + +// object expect +supertest(app) + .get('/') + .expect(200, { foo: 'bar' }) + .end((err: any, res: supertest.Response) => { + if (err) throw err; + });