From 3e13cd8e459f428a6e46d993f853f77394d29d78 Mon Sep 17 00:00:00 2001 From: songawee Date: Thu, 6 Oct 2016 16:45:29 -0600 Subject: [PATCH] use object type for body in expect fn arguments --- supertest/supertest-tests.ts | 18 +++++++++++++----- supertest/supertest.d.ts | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/supertest/supertest-tests.ts b/supertest/supertest-tests.ts index 5e0de8ad8c..ce01551ef9 100644 --- a/supertest/supertest-tests.ts +++ b/supertest/supertest-tests.ts @@ -4,7 +4,7 @@ import * as supertest from 'supertest'; import * as express from 'express'; -var app = express(); +const app = express(); supertest(app) .get('/user') @@ -16,15 +16,15 @@ supertest(app) }); // 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; @@ -32,7 +32,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) => { @@ -56,3 +56,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; + }); diff --git a/supertest/supertest.d.ts b/supertest/supertest.d.ts index 5793483300..7aa5d14d64 100644 --- a/supertest/supertest.d.ts +++ b/supertest/supertest.d.ts @@ -23,7 +23,7 @@ declare module "supertest" { url: string; serverAddress(app: any, path: string): string; expect(status: number, callback?: CallbackHandler): this; - expect(status: number, body: string, 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;