mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
supertest-as-promised
See https://github.com/WhoopInc/supertest-as-promised
This commit is contained in:
parent
16134c168d
commit
5a1c6dc6ac
64
supertest-as-promised/supertest-as-promised-tests.ts
Normal file
64
supertest-as-promised/supertest-as-promised-tests.ts
Normal file
@ -0,0 +1,64 @@
|
||||
/// <reference path="supertest-as-promised.d.ts" />
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
/// <reference path="../jasmine/jasmine.d.ts" />
|
||||
|
||||
import * as request from 'supertest-as-promised';
|
||||
import * as express from 'express';
|
||||
|
||||
var app = express();
|
||||
|
||||
// chain your requests like you were promised:
|
||||
request(app)
|
||||
.get("/user")
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
return request(app)
|
||||
.post("/kittens")
|
||||
.send({ userId: res})
|
||||
.expect(201);
|
||||
})
|
||||
.then(function (res) {
|
||||
// ...
|
||||
});
|
||||
|
||||
|
||||
// Usage
|
||||
request(app)
|
||||
.get("/kittens")
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
// ...
|
||||
});
|
||||
|
||||
describe("GET /kittens", function () {
|
||||
it("should work", function () {
|
||||
return request(app).get("/kittens").expect(200);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Agents
|
||||
var agent = request.agent(app);
|
||||
agent
|
||||
.get("/ugly-kitteh")
|
||||
.expect(404)
|
||||
.then(function () {
|
||||
// ...
|
||||
})
|
||||
|
||||
|
||||
// Promisey goodness
|
||||
request(app)
|
||||
.get("/kittens")
|
||||
.expect(201)
|
||||
.then(function (res) { /* ... */ })
|
||||
// I'm a real promise now!
|
||||
.catch(function (err) { /* ... */ })
|
||||
|
||||
request(app)
|
||||
.get("/kittens")
|
||||
.expect(201)
|
||||
.toPromise()
|
||||
// I'm a real promise now!
|
||||
.delay(10)
|
||||
.then(function (res) { /* ... */ })
|
||||
45
supertest-as-promised/supertest-as-promised.d.ts
vendored
Normal file
45
supertest-as-promised/supertest-as-promised.d.ts
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Type definitions for SuperTest as Promised v2.0.2
|
||||
// Project: https://github.com/WhoopInc/supertest-as-promised
|
||||
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path='../superagent/superagent.d.ts' />
|
||||
/// <reference path="../bluebird/bluebird.d.ts" />
|
||||
|
||||
declare module "supertest-as-promised" {
|
||||
// Mostly copy-pasted from supertest.d.ts
|
||||
|
||||
import * as superagent from 'superagent';
|
||||
import * as PromiseBluebird from 'bluebird';
|
||||
|
||||
function supertest(app: any): supertest.SuperTest;
|
||||
|
||||
module supertest {
|
||||
function agent(app?: any): supertest.SuperTest;
|
||||
|
||||
interface SuperTest extends superagent.SuperAgent<Test> {
|
||||
}
|
||||
|
||||
interface Promise<T> extends PromiseBluebird<T> {
|
||||
toPromise(): PromiseBluebird<T>;
|
||||
}
|
||||
|
||||
interface Test extends superagent.Request<Test> {
|
||||
url: string;
|
||||
serverAddress(app: any, path: string): string;
|
||||
expect(status: number): Promise<supertest.Response>;
|
||||
expect(status: number, body: string): Promise<supertest.Response>;
|
||||
expect(body: string): Promise<supertest.Response>;
|
||||
expect(body: RegExp): Promise<supertest.Response>;
|
||||
expect(body: Object): Promise<supertest.Response>;
|
||||
expect(field: string, val: string): Promise<supertest.Response>;
|
||||
expect(field: string, val: RegExp): Promise<supertest.Response>;
|
||||
expect(checker: (res: Response) => any): Promise<supertest.Response>;
|
||||
}
|
||||
|
||||
interface Response extends superagent.Response {
|
||||
}
|
||||
}
|
||||
|
||||
export = supertest;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user