From 8fb8a60fe20bcc6dc9ea6ec4ccbb841885841637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fa=CC=81bio=20Batista?= Date: Sat, 2 Sep 2017 21:48:47 -0300 Subject: [PATCH] chai-http: added Request.parse() and friends --- types/chai-http/chai-http-tests.ts | 10 ++++++++++ types/chai-http/index.d.ts | 3 +++ 2 files changed, 13 insertions(+) diff --git a/types/chai-http/chai-http-tests.ts b/types/chai-http/chai-http-tests.ts index 7c1c7a6b42..f4f65cae7b 100644 --- a/types/chai-http/chai-http-tests.ts +++ b/types/chai-http/chai-http-tests.ts @@ -41,6 +41,16 @@ chai.request(app) .get('/search') .query({ name: 'foo', limit: 10 }); +chai.request(app) + .get('/download') + .buffer() + .parse((res, cb) => { + let data = ''; + res.setEncoding('binary'); + res.on('data', (chunk: any) => { data += chunk; }); + res.on('end', () => { cb(undefined, new Buffer(data, 'binary')); }); + }); + chai.request(app) .put('/user/me') .send({ passsword: '123', confirmPassword: '123' }) diff --git a/types/chai-http/index.d.ts b/types/chai-http/index.d.ts index f0957cc454..6a9404c9da 100644 --- a/types/chai-http/index.d.ts +++ b/types/chai-http/index.d.ts @@ -49,6 +49,8 @@ declare global { type: string; status: number; text: string; + setEncoding(encoding: string): void; + on(event: string, fn: (...args: any[]) => void): void; } interface Request extends FinishedRequest { @@ -59,6 +61,7 @@ declare global { auth(user: string, name: string): Request; field(name: string, val: string): Request; buffer(): Request; + parse(fn: (res: Response, cb: (e?: Error, r?: any) => void) => void): Request; end(callback?: (err: any, res: Response) => void): FinishedRequest; }