Merge pull request #19526 from fabiob/master

chai-http: added Request.parse() method and friends
This commit is contained in:
Nathan Shively-Sanders
2017-09-05 15:43:24 -07:00
committed by GitHub
2 changed files with 13 additions and 0 deletions

View File

@@ -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' })

View File

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