From ffbf9da05fd9fe404a250586b15b7a3276bfe7cc Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Tue, 10 Jul 2018 11:39:22 -0500 Subject: [PATCH] chai-http: Add methods keepOpen() and close() to the agent (#27153) keepOpen() and close() are available both on the base request and on the agent for controlling the lifetime of the server. --- types/chai-http/chai-http-tests.ts | 6 ++++++ types/chai-http/index.d.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/types/chai-http/chai-http-tests.ts b/types/chai-http/chai-http-tests.ts index 882f089a47..37a4df794e 100644 --- a/types/chai-http/chai-http-tests.ts +++ b/types/chai-http/chai-http-tests.ts @@ -84,6 +84,10 @@ chai.request(app) .then((res: ChaiHttp.Response) => chai.expect(res).to.have.status(200)) .catch((err: any) => { throw err; }); +chai.request(app) + .keepOpen() + .close((err: any) => { throw err; }); + const agent = chai.request.agent(app); agent @@ -97,6 +101,8 @@ agent .then((res: ChaiHttp.Response) => chai.expect(res).to.have.status(200)); }); +agent.close((err: any) => { throw err; }); + function test1() { const req = chai.request(app).get('/'); req.then((res: ChaiHttp.Response) => { diff --git a/types/chai-http/index.d.ts b/types/chai-http/index.d.ts index 77c711cb7f..de3caa13e7 100644 --- a/types/chai-http/index.d.ts +++ b/types/chai-http/index.d.ts @@ -64,6 +64,8 @@ declare global { del(url: string, callback?: (err: any, res: Response) => void): request.Request; options(url: string, callback?: (err: any, res: Response) => void): request.Request; patch(url: string, callback?: (err: any, res: Response) => void): request.Request; + keepOpen(): Agent; + close(callback?: (err: any) => void): Agent; } interface TypeComparison {