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.
This commit is contained in:
Brian Crowell
2018-07-10 11:39:22 -05:00
committed by Ryan Cavanaugh
parent 83f67fa71c
commit ffbf9da05f
2 changed files with 8 additions and 0 deletions

View File

@@ -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) => {

View File

@@ -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 {