mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Expose agent on supertest and cookie methods on superagent
This commit is contained in:
parent
429cfd875e
commit
ab5886b01f
2
superagent/superagent.d.ts
vendored
2
superagent/superagent.d.ts
vendored
@ -79,6 +79,8 @@ declare module "superagent" {
|
||||
unsubscribe(url: string, callback?: (err: Error, res: Response) => void): Request;
|
||||
patch(url: string, callback?: (err: Error, res: Response) => void): Request;
|
||||
parse(fn: Function): Request;
|
||||
saveCookies(res: Response): void;
|
||||
attachCookies(req: Request): void;
|
||||
}
|
||||
|
||||
export function agent(): Agent;
|
||||
|
||||
@ -14,3 +14,19 @@ supertest(app)
|
||||
.end((err, res) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
// cookie scenario
|
||||
var request = supertest(app);
|
||||
var agent = supertest.agent();
|
||||
request
|
||||
.post('/login')
|
||||
.end((err, res) => {
|
||||
if (err) throw err;
|
||||
agent.saveCookies(res);
|
||||
|
||||
var req = request.get('/admin');
|
||||
agent.attachCookies(req);
|
||||
req.expect(200, (err, res) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
});
|
||||
2
supertest/supertest.d.ts
vendored
2
supertest/supertest.d.ts
vendored
@ -46,6 +46,8 @@ declare module "supertest" {
|
||||
unsubscribe(url: string): Test;
|
||||
patch(url: string): Test;
|
||||
}
|
||||
|
||||
function agent(): superagent.Agent;
|
||||
}
|
||||
|
||||
function supertest(app: any): supertest.SuperTest;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user