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; }