mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Merge pull request #11814 from songawee/fix_supertest_expect
use object type for body in supertest expect fn arguments
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
import * as supertest from 'supertest';
|
||||
import * as express from 'express';
|
||||
|
||||
var app = express();
|
||||
const app = express();
|
||||
|
||||
supertest(app)
|
||||
.get('/user')
|
||||
@@ -16,15 +16,15 @@ supertest(app)
|
||||
});
|
||||
|
||||
// cookie scenario
|
||||
var request = supertest(app);
|
||||
var agent = supertest.agent();
|
||||
const request = supertest(app);
|
||||
const agent = supertest.agent();
|
||||
request
|
||||
.post('/login')
|
||||
.end((err: any, res: supertest.Response) => {
|
||||
if (err) throw err;
|
||||
agent.saveCookies(res);
|
||||
|
||||
var req = request.get('/admin');
|
||||
const req = request.get('/admin');
|
||||
agent.attachCookies(req);
|
||||
req.expect(200, (err: any, res: supertest.Response) => {
|
||||
if (err) throw err;
|
||||
@@ -32,7 +32,7 @@ request
|
||||
});
|
||||
|
||||
// cookie scenario, new version
|
||||
var client = supertest.agent(app);
|
||||
const client = supertest.agent(app);
|
||||
client
|
||||
.post('/login')
|
||||
.end((err: any, res: supertest.Response) => {
|
||||
@@ -56,3 +56,11 @@ function hasPreviousAndNextKeys(res: supertest.Response) {
|
||||
if (!('next' in res.body)) return "missing next key";
|
||||
if (!('prev' in res.body)) throw new Error("missing prev key");
|
||||
}
|
||||
|
||||
// object expect
|
||||
supertest(app)
|
||||
.get('/')
|
||||
.expect(200, { foo: 'bar' })
|
||||
.end((err: any, res: supertest.Response) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
Vendored
+1
-1
@@ -23,7 +23,7 @@ declare module "supertest" {
|
||||
url: string;
|
||||
serverAddress(app: any, path: string): string;
|
||||
expect(status: number, callback?: CallbackHandler): this;
|
||||
expect(status: number, body: string, callback?: CallbackHandler): this;
|
||||
expect(status: number, body: any, callback?: CallbackHandler): this;
|
||||
expect(body: string, callback?: CallbackHandler): this;
|
||||
expect(body: RegExp, callback?: CallbackHandler): this;
|
||||
expect(body: Object, callback?: CallbackHandler): this;
|
||||
|
||||
Reference in New Issue
Block a user