mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-12 12:10:44 +08:00
Fix chai libraries, plugins
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
/// <reference path="../when/when.d.ts" />
|
||||
/// <reference path="./chai-http.d.ts" />
|
||||
/// <reference path="chai-http.d.ts" />
|
||||
|
||||
import fs = require('fs');
|
||||
import http = require('http');
|
||||
import chai = require('chai');
|
||||
import chaiHttp = require('chai-http');
|
||||
import ChaiHttp = require('chai-http');
|
||||
import when = require('when');
|
||||
|
||||
chai.use(chaiHttp);
|
||||
chai.use(ChaiHttp);
|
||||
|
||||
// ReSharper disable WrongExpressionStatement
|
||||
|
||||
// Add promise support if this does not exist natively.
|
||||
if (!global.Promise) {
|
||||
chai.request.addPromises(when.promise);
|
||||
}
|
||||
|
||||
|
||||
var app: http.Server;
|
||||
|
||||
chai.request(app).get('/');
|
||||
@@ -47,7 +48,7 @@ chai.request(app)
|
||||
chai.request(app)
|
||||
.put('/user/me')
|
||||
.send({ passsword: '123', confirmPassword: '123' })
|
||||
.end((err: any, res: chaiHttp.Response) => {
|
||||
.end((err: any, res: ChaiHttp.Response) => {
|
||||
chai.expect(err).to.be.null;
|
||||
chai.expect(res).to.have.status(200);
|
||||
});
|
||||
@@ -55,7 +56,7 @@ chai.request(app)
|
||||
chai.request(app)
|
||||
.put('/user/me')
|
||||
.send({ passsword: '123', confirmPassword: '123' })
|
||||
.then((res: chaiHttp.Response) => chai.expect(res).to.have.status(200))
|
||||
.then((res: ChaiHttp.Response) => chai.expect(res).to.have.status(200))
|
||||
.catch((err: any) => { throw err; });
|
||||
|
||||
var agent = chai.request.agent(app);
|
||||
@@ -63,17 +64,17 @@ var agent = chai.request.agent(app);
|
||||
agent
|
||||
.post('/session')
|
||||
.send({ username: 'me', password: '123' })
|
||||
.then((res: chaiHttp.Response) => {
|
||||
.then((res: ChaiHttp.Response) => {
|
||||
chai.expect(res).to.have.cookie('sessionid');
|
||||
// The `agent` now has the sessionid cookie saved, and will send it
|
||||
// back to the server in the next request:
|
||||
return agent.get('/user/me')
|
||||
.then((res: chaiHttp.Response) => chai.expect(res).to.have.status(200));
|
||||
.then((res: ChaiHttp.Response) => chai.expect(res).to.have.status(200));
|
||||
});
|
||||
|
||||
function test1() {
|
||||
var req = chai.request(app).get('/');
|
||||
req.then((res: chaiHttp.Response) => {
|
||||
req.then((res: ChaiHttp.Response) => {
|
||||
chai.expect(res).to.have.status(200);
|
||||
chai.expect(res).to.have.header('content-type', 'text/plain');
|
||||
chai.expect(res).to.have.header('content-type', /^text/);
|
||||
@@ -99,5 +100,4 @@ function test1() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
when(chai.request(app).get('/')).done(() => console.log('success'), () => console.log('failure'));
|
||||
|
||||
Vendored
+26
-29
@@ -6,27 +6,38 @@
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
|
||||
declare module chai {
|
||||
export function request(server: any): chaiHttp.Agent;
|
||||
declare module Chai {
|
||||
|
||||
export module request {
|
||||
export function agent(server: any): chaiHttp.Agent;
|
||||
export function addPromises(promiseConstructor: chaiHttp.PromiseConstructor): void;
|
||||
interface ChaiStatic {
|
||||
request: ChaiHttpRequest;
|
||||
}
|
||||
|
||||
interface Assertions extends chaiHttp.Assertions {
|
||||
interface ChaiHttpRequest {
|
||||
(server: any): ChaiHttp.Agent;
|
||||
agent(server: any): ChaiHttp.Agent;
|
||||
addPromises(promiseConstructor: any): void;
|
||||
}
|
||||
|
||||
interface TypeComparison extends chaiHttp.TypeComparison {
|
||||
interface Assertion {
|
||||
status(code: number): Assertion;
|
||||
header(key: string, value?: string): Assertion;
|
||||
header(key: string, value?: RegExp): Assertion;
|
||||
headers: Assertion;
|
||||
json: Assertion;
|
||||
text: Assertion;
|
||||
html: Assertion;
|
||||
redirect: Assertion;
|
||||
redirectTo(location: string): Assertion;
|
||||
param(key: string, value?: string): Assertion;
|
||||
cookie(key: string, value?: string): Assertion;
|
||||
}
|
||||
|
||||
interface TypeComparison {
|
||||
ip: Assertion;
|
||||
}
|
||||
}
|
||||
|
||||
declare function chaiHttp(chai: any, utils: any): void;
|
||||
declare module chaiHttp {
|
||||
interface PromiseConstructor {
|
||||
<T>(resolver: (resolve: (value: T) => void, reject: (reason: any) => void) => void): Promise<T>;
|
||||
}
|
||||
|
||||
declare module ChaiHttp {
|
||||
interface Promise<T> {
|
||||
then<U>(onFulfilled: (value: T) => U, onRejected?: (reason: any) => U): Promise<U>;
|
||||
}
|
||||
@@ -38,8 +49,7 @@ declare module chaiHttp {
|
||||
}
|
||||
|
||||
interface Request extends FinishedRequest {
|
||||
attach(field: string, file: string, filename: string): Request;
|
||||
attach(field: string, file: Buffer, filename: string): Request;
|
||||
attach(field: string, file: string|Buffer, filename: string): Request;
|
||||
set(field: string, val: string): Request;
|
||||
query(key: string, value: string): Request;
|
||||
send(data: Object): Request;
|
||||
@@ -63,25 +73,12 @@ declare module chaiHttp {
|
||||
patch(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
}
|
||||
|
||||
interface Assertions {
|
||||
status(code: number): any;
|
||||
header(key: string, value?: string): any;
|
||||
header(key: string, value?: RegExp): any;
|
||||
headers: any;
|
||||
json: any;
|
||||
// text: any;
|
||||
// html: any;
|
||||
redirect: any;
|
||||
redirectTo(location: string): any;
|
||||
param(key: string, value?: string): any;
|
||||
cookie(key: string, value?: string): any;
|
||||
}
|
||||
|
||||
interface TypeComparison {
|
||||
ip: any;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "chai-http" {
|
||||
function chaiHttp(chai: any, utils: any): void;
|
||||
export = chaiHttp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user