mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-17 11:45:58 +08:00
@@ -1,4 +1,3 @@
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
/// <reference path="chai-as-promised.d.ts" />
|
||||
|
||||
import chai = require('chai');
|
||||
@@ -6,6 +5,7 @@ import chaiAsPromised = require('chai-as-promised');
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
|
||||
// ReSharper disable WrongExpressionStatement
|
||||
var promise: any;
|
||||
chai.expect(promise).to.eventually.equal(3);
|
||||
chai.expect(promise).to.become(3);
|
||||
|
||||
20
chai-as-promised/chai-as-promised.d.ts
vendored
20
chai-as-promised/chai-as-promised.d.ts
vendored
@@ -6,21 +6,21 @@
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
|
||||
declare module 'chai-as-promised' {
|
||||
import chai = require('chai');
|
||||
|
||||
function chaiAsPromised(chai: any, utils: any): void;
|
||||
|
||||
export = chaiAsPromised;
|
||||
}
|
||||
|
||||
declare module chai {
|
||||
declare module Chai {
|
||||
|
||||
interface Assertion {
|
||||
become(expected: any): Assertion;
|
||||
rejected: Assertion;
|
||||
rejectedWith(expected: any): Assertion;
|
||||
notify(fn: Function): Assertion;
|
||||
}
|
||||
|
||||
interface LanguageChains {
|
||||
become(expected: any): Expect;
|
||||
eventually: Expect;
|
||||
rejected: Expect;
|
||||
rejectedWith(expected: any): Expect;
|
||||
notify(fn: Function): Expect;
|
||||
eventually: Assertion;
|
||||
}
|
||||
|
||||
interface Assert {
|
||||
@@ -32,4 +32,4 @@ declare module chai {
|
||||
isRejected(promise: any, expected: any, message?: string): void;
|
||||
isRejected(promise: any, match: RegExp, message?: string): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
/// <reference path="chai-datetime.d.ts" />
|
||||
|
||||
import chai = require('chai');
|
||||
import chaiDateTime = require('chai-datetime');
|
||||
|
||||
chai.use(chaiDateTime);
|
||||
var expect = chai.expect;
|
||||
var assert = chai.assert;
|
||||
|
||||
function test_equalTime(){
|
||||
var date: Date = new Date(2014, 1, 1);
|
||||
expect(date).to.be.equalTime(date);
|
||||
date.should.be.equalTime(date);
|
||||
expect(date).to.equalTime(date);
|
||||
date.should.equalTime(date);
|
||||
assert.equalTime(date, date);
|
||||
}
|
||||
|
||||
@@ -34,14 +37,14 @@ function test_equalDate(){
|
||||
|
||||
function test_beforeDate(){
|
||||
var date: Date = new Date(2014, 1, 1);
|
||||
expect(date).to.beforeDate(date);
|
||||
date.should.beforeDate(date);
|
||||
expect(date).to.be.beforeDate(date);
|
||||
date.should.be.beforeDate(date);
|
||||
assert.beforeDate(date, date);
|
||||
}
|
||||
|
||||
function test_afterDate(){
|
||||
var date: Date = new Date(2014, 1, 1);
|
||||
expect(date).to.afterDate(date);
|
||||
date.should.afterDate(date);
|
||||
expect(date).to.be.afterDate(date);
|
||||
date.should.be.afterDate(date);
|
||||
assert.afterDate(date, date);
|
||||
}
|
||||
|
||||
55
chai-datetime/chai-datetime.d.ts
vendored
55
chai-datetime/chai-datetime.d.ts
vendored
@@ -5,35 +5,38 @@
|
||||
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
|
||||
declare module chai {
|
||||
declare module Chai {
|
||||
|
||||
interface Expect {
|
||||
afterDate(date: Date): boolean;
|
||||
beforeDate(date: Date): boolean;
|
||||
equalDate(date: Date): boolean;
|
||||
interface Assertion {
|
||||
afterDate(date: Date): Assertion;
|
||||
beforeDate(date: Date): Assertion;
|
||||
equalDate(date: Date): Assertion;
|
||||
afterTime(date: Date): Assertion;
|
||||
beforeTime(date: Date): Assertion;
|
||||
equalTime(date: Date): Assertion;
|
||||
}
|
||||
|
||||
afterTime(date: Date): boolean;
|
||||
beforeTime(date: Date): boolean;
|
||||
equalTime(date: Date): boolean;
|
||||
}
|
||||
|
||||
interface Assert {
|
||||
equalTime(val: Date, exp: Date, msg?: string): boolean;
|
||||
notEqualTime(val: Date, exp: Date, msg?: string): boolean;
|
||||
beforeTime(val: Date, exp: Date, msg?: string): boolean;
|
||||
notBeforeTime(val: Date, exp: Date, msg?: string): boolean;
|
||||
afterTime(val: Date, exp: Date, msg?: string): boolean;
|
||||
notAfterTime(val: Date, exp: Date, msg?: string): boolean;
|
||||
|
||||
equalDate(val: Date, exp: Date, msg?: string): boolean;
|
||||
notEqualDate(val: Date, exp: Date, msg?: string): boolean;
|
||||
beforeDate(val: Date, exp: Date, msg?: string): boolean;
|
||||
notBeforeDate(val: Date, exp: Date, msg?: string): boolean;
|
||||
afterDate(val: Date, exp: Date, msg?: string): boolean;
|
||||
notAfterDate(val: Date, exp: Date, msg?: string): boolean;
|
||||
}
|
||||
interface Assert {
|
||||
equalTime(val: Date, exp: Date, msg?: string): void;
|
||||
notEqualTime(val: Date, exp: Date, msg?: string): void;
|
||||
beforeTime(val: Date, exp: Date, msg?: string): void;
|
||||
notBeforeTime(val: Date, exp: Date, msg?: string): void;
|
||||
afterTime(val: Date, exp: Date, msg?: string): void;
|
||||
notAfterTime(val: Date, exp: Date, msg?: string): void;
|
||||
equalDate(val: Date, exp: Date, msg?: string): void;
|
||||
notEqualDate(val: Date, exp: Date, msg?: string): void;
|
||||
beforeDate(val: Date, exp: Date, msg?: string): void;
|
||||
notBeforeDate(val: Date, exp: Date, msg?: string): void;
|
||||
afterDate(val: Date, exp: Date, msg?: string): void;
|
||||
notAfterDate(val: Date, exp: Date, msg?: string): void;
|
||||
}
|
||||
}
|
||||
|
||||
interface Date {
|
||||
should: chai.Expect;
|
||||
should: Chai.Assertion;
|
||||
}
|
||||
|
||||
declare module "chai-datetime" {
|
||||
function chaiDateTime(chai: any, utils: any): void;
|
||||
export = chaiDateTime;
|
||||
}
|
||||
|
||||
35
chai-fuzzy/chai-fuzzy-tests.ts
Normal file
35
chai-fuzzy/chai-fuzzy-tests.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/// <reference path="chai-fuzzy.d.ts" />
|
||||
|
||||
// tests taken from http://chaijs.com/plugins/chai-fuzzy
|
||||
|
||||
import chai = require('chai');
|
||||
import chaiFuzzy = require('chai-fuzzy');
|
||||
|
||||
chai.use(chaiFuzzy);
|
||||
var expect = chai.expect;
|
||||
var assert = chai.assert;
|
||||
|
||||
/**
|
||||
* compare object attributes and values rather than checking to see if they're the same reference
|
||||
*/
|
||||
function like() {
|
||||
var subject = { a: 'a' };
|
||||
|
||||
expect(subject).to.be.like({ a: 'a' });
|
||||
expect(subject).not.to.be.like({ x: 'x' });
|
||||
expect(subject).not.to.be.like({ a: 'a', b: 'b' });
|
||||
|
||||
assert.like(subject, { a: 'a' });
|
||||
assert.notLike(subject, { x: 'x' });
|
||||
assert.notLike(subject, { a: 'a', b: 'b' });
|
||||
|
||||
var subject2 = ['a'];
|
||||
|
||||
expect(subject2).to.be.like(['a']);
|
||||
expect(subject2).not.to.be.like(['x']);
|
||||
expect(subject2).not.to.be.like(['a', 'b']);
|
||||
|
||||
assert.like(subject2, ['a']);
|
||||
assert.notLike(subject2, ['x']);
|
||||
assert.notLike(subject2, ['a', 'b']);
|
||||
}
|
||||
75
chai-fuzzy/chai-fuzzy.d.ts
vendored
75
chai-fuzzy/chai-fuzzy.d.ts
vendored
@@ -5,13 +5,72 @@
|
||||
|
||||
///<reference path="../chai/chai.d.ts" />
|
||||
|
||||
declare module chai {
|
||||
interface Assert {
|
||||
like(act:any, exp:any, msg?:string);
|
||||
notLike(act:any, exp:any, msg?:string);
|
||||
containOneLike(act:any, exp:any, msg?:string);
|
||||
notContainOneLike(act:any, exp:any, msg?:string);
|
||||
jsonOf(act:any, exp:any, msg?:string);
|
||||
notJsonOf(act:any, exp:any, msg?:string);
|
||||
declare module Chai {
|
||||
|
||||
interface Assertion {
|
||||
/**
|
||||
* Compare object attributes and values rather than checking to see if
|
||||
* they're the same reference.
|
||||
*/
|
||||
like(expected: any, message?: string): Assertion;
|
||||
/**
|
||||
* Compare object attributes and values rather than checking to see if
|
||||
* they're the same reference.
|
||||
*/
|
||||
notLike(expected: any, message?: string): Assertion;
|
||||
/**
|
||||
* Check the first level of the container for a value like the one provided.
|
||||
*/
|
||||
containOneLike(expected: any, message?: string): Assertion;
|
||||
/**
|
||||
* Check the first level of the container for a value like the one provided.
|
||||
*/
|
||||
notContainOneLike(expected: any, message?: string): Assertion;
|
||||
/**
|
||||
* Check that the given javascript object is like the JSON-ified expected
|
||||
* value. Useful for checking stringification and parsing of an object.
|
||||
*/
|
||||
jsonOf(expected: any, message?: string): Assertion;
|
||||
/**
|
||||
* Check that the given javascript object is like the JSON-ified expected
|
||||
* value. Useful for checking stringification and parsing of an object.
|
||||
*/
|
||||
notJsonOf(expected: any, message?: string): Assertion;
|
||||
}
|
||||
|
||||
export interface Assert {
|
||||
/**
|
||||
* Compare object attributes and values rather than checking to see if
|
||||
* they're the same reference.
|
||||
*/
|
||||
like(actual: any, expected: any, message?: string): void;
|
||||
/**
|
||||
* Compare object attributes and values rather than checking to see if
|
||||
* they're the same reference.
|
||||
*/
|
||||
notLike(actual: any, expected: any, message?: string): void;
|
||||
/**
|
||||
* Check the first level of the container for a value like the one provided.
|
||||
*/
|
||||
containOneLike(actual: any, expected: any, message?: string): void;
|
||||
/**
|
||||
* Check the first level of the container for a value like the one provided.
|
||||
*/
|
||||
notContainOneLike(actual: any, expected: any, message?: string): void;
|
||||
/**
|
||||
* Check that the given javascript object is like the JSON-ified expected
|
||||
* value. Useful for checking stringification and parsing of an object.
|
||||
*/
|
||||
jsonOf(actual: any, expected: any, message?: string): void;
|
||||
/**
|
||||
* Check that the given javascript object is like the JSON-ified expected
|
||||
* value. Useful for checking stringification and parsing of an object.
|
||||
*/
|
||||
notJsonOf(actual: any, expected: any, message?: string): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "chai-fuzzy" {
|
||||
function chaiFuzzy(chai: any, utils: any): void;
|
||||
export = chaiFuzzy;
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -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'));
|
||||
|
||||
55
chai-http/chai-http.d.ts
vendored
55
chai-http/chai-http.d.ts
vendored
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
/// <reference path="chai-jquery.d.ts" />
|
||||
|
||||
// tests taken from https://github.com/chaijs/chai-jquery
|
||||
|
||||
declare var $;
|
||||
declare var $: ChaiJQueryStatic;
|
||||
import chai = require('chai');
|
||||
var expect = chai.expect;
|
||||
|
||||
function test_attr() {
|
||||
@@ -19,7 +19,7 @@ function test_css() {
|
||||
function test_data() {
|
||||
expect($('#foo')).to.have.data('toggle');
|
||||
expect($('#foo')).to.have.css('toggle', 'true');
|
||||
expect($('body')).to.have.css('font-family').match(/sans-serif/);
|
||||
expect($('body')).to.have.css('font-family').and.match(/sans-serif/);
|
||||
}
|
||||
|
||||
function test_class() {
|
||||
@@ -88,4 +88,4 @@ function test_be_selector() {
|
||||
function test_have_selector() {
|
||||
$('body').should.have('h1');
|
||||
expect($('#foo')).to.have('div');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
2597
chai-jquery/chai-jquery.d.ts
vendored
2597
chai-jquery/chai-jquery.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1451
chai/chai-tests.ts
1451
chai/chai-tests.ts
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
|
||||
315
chai/chai.d.ts
vendored
315
chai/chai.d.ts
vendored
@@ -1,67 +1,46 @@
|
||||
// Type definitions for chai 2.0.0
|
||||
// Project: http://chaijs.com/
|
||||
// Definitions by: Jed Hunsaker <https://github.com/jedhunsaker/>, Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions by: Jed Mao <https://github.com/jedmao/>, Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module chai {
|
||||
export class AssertionError {
|
||||
constructor(message: string, _props?: any, ssf?: Function);
|
||||
name: string;
|
||||
message: string;
|
||||
showDiff: boolean;
|
||||
stack: string;
|
||||
declare module Chai {
|
||||
|
||||
interface ChaiStatic {
|
||||
expect: ExpectStatic;
|
||||
/**
|
||||
* Provides a way to extend the internals of Chai
|
||||
*/
|
||||
use(fn: (chai: any, utils: any) => void): any;
|
||||
assert: AssertStatic;
|
||||
config: Config;
|
||||
}
|
||||
|
||||
export function expect(target: any, message?: string): Expect;
|
||||
|
||||
export var assert: Assert;
|
||||
export var config: Config;
|
||||
|
||||
export interface Config {
|
||||
includeStack: boolean;
|
||||
export interface ExpectStatic extends AssertionStatic {
|
||||
}
|
||||
|
||||
// Provides a way to extend the internals of Chai
|
||||
function use(fn: (chai: any, utils: any) => void): any;
|
||||
|
||||
interface ExpectStatic {
|
||||
(target: any): Expect;
|
||||
export interface AssertStatic extends Assert {
|
||||
}
|
||||
|
||||
interface Assertions {
|
||||
attr(name: string, value?: string): any;
|
||||
css(name: string, value?: string): any;
|
||||
data(name: string, value?: string): any;
|
||||
class(className: string): any;
|
||||
id(id: string): any;
|
||||
html(html: string): any;
|
||||
text(text: string): any;
|
||||
value(value: string): any;
|
||||
visible: any;
|
||||
hidden: any;
|
||||
selected: any;
|
||||
checked: any;
|
||||
disabled: any;
|
||||
empty: any;
|
||||
exist: any;
|
||||
export interface AssertionStatic {
|
||||
(target: any, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface Expect extends LanguageChains, NumericComparison, TypeComparison, Assertions {
|
||||
not: Expect;
|
||||
interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
|
||||
not: Assertion;
|
||||
deep: Deep;
|
||||
a: TypeComparison;
|
||||
an: TypeComparison;
|
||||
include: Include;
|
||||
contain: Include;
|
||||
ok: Expect;
|
||||
true: Expect;
|
||||
false: Expect;
|
||||
null: Expect;
|
||||
undefined: Expect;
|
||||
exist: Expect;
|
||||
empty: Expect;
|
||||
arguments: Expect;
|
||||
Arguments: Expect;
|
||||
ok: Assertion;
|
||||
true: Assertion;
|
||||
false: Assertion;
|
||||
null: Assertion;
|
||||
undefined: Assertion;
|
||||
exist: Assertion;
|
||||
empty: Assertion;
|
||||
arguments: Assertion;
|
||||
Arguments: Assertion;
|
||||
equal: Equal;
|
||||
equals: Equal;
|
||||
eq: Equal;
|
||||
@@ -72,34 +51,34 @@ declare module chai {
|
||||
haveOwnProperty: OwnProperty;
|
||||
length: Length;
|
||||
lengthOf: Length;
|
||||
match(RegularExpression: RegExp, message?: string): Expect;
|
||||
string(string: string, message?: string): Expect;
|
||||
match(regexp: RegExp|string, message?: string): Assertion;
|
||||
string(string: string, message?: string): Assertion;
|
||||
keys: Keys;
|
||||
key(string: string): Expect;
|
||||
key(string: string): Assertion;
|
||||
throw: Throw;
|
||||
throws: Throw;
|
||||
Throw: Throw;
|
||||
respondTo(method: string, message?: string): Expect;
|
||||
itself: Expect;
|
||||
satisfy(matcher: Function, message?: string): Expect;
|
||||
closeTo(expected: number, delta: number, message?: string): Expect;
|
||||
respondTo(method: string, message?: string): Assertion;
|
||||
itself: Assertion;
|
||||
satisfy(matcher: Function, message?: string): Assertion;
|
||||
closeTo(expected: number, delta: number, message?: string): Assertion;
|
||||
members: Members;
|
||||
}
|
||||
|
||||
interface LanguageChains {
|
||||
to: Expect;
|
||||
be: Expect;
|
||||
been: Expect;
|
||||
is: Expect;
|
||||
that: Expect;
|
||||
which: Expect;
|
||||
and: Expect;
|
||||
have: Expect;
|
||||
has: Expect;
|
||||
with: Expect;
|
||||
at: Expect;
|
||||
of: Expect;
|
||||
same: Expect;
|
||||
to: Assertion;
|
||||
be: Assertion;
|
||||
been: Assertion;
|
||||
is: Assertion;
|
||||
that: Assertion;
|
||||
which: Assertion;
|
||||
and: Assertion;
|
||||
has: Assertion;
|
||||
have: Assertion;
|
||||
with: Assertion;
|
||||
at: Assertion;
|
||||
of: Assertion;
|
||||
same: Assertion;
|
||||
}
|
||||
|
||||
interface NumericComparison {
|
||||
@@ -113,21 +92,21 @@ declare module chai {
|
||||
lessThan: NumberComparer;
|
||||
most: NumberComparer;
|
||||
lte: NumberComparer;
|
||||
within(start: number, finish: number, message?: string): Expect;
|
||||
within(start: number, finish: number, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface NumberComparer {
|
||||
(value: number, message?: string): Expect;
|
||||
(value: number, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface TypeComparison {
|
||||
(type: string, message?: string): Expect;
|
||||
(type: string, message?: string): Assertion;
|
||||
instanceof: InstanceOf;
|
||||
instanceOf: InstanceOf;
|
||||
}
|
||||
|
||||
interface InstanceOf {
|
||||
(constructor: Object, message?: string): Expect;
|
||||
(constructor: Object, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface Deep {
|
||||
@@ -137,150 +116,168 @@ declare module chai {
|
||||
}
|
||||
|
||||
interface Equal {
|
||||
(value: any, message?: string): Expect;
|
||||
(value: any, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface Property {
|
||||
(name: string, value?: any, message?: string): Expect;
|
||||
(name: string, value?: any, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface OwnProperty {
|
||||
(name: string, message?: string): Expect;
|
||||
(name: string, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface Length extends LanguageChains, NumericComparison {
|
||||
(length: number, message?: string): Expect;
|
||||
(length: number, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface Include {
|
||||
(value: Object, message?: string): Expect;
|
||||
(value: string, message?: string): Expect;
|
||||
(value: number, message?: string): Expect;
|
||||
(value: Object, message?: string): Assertion;
|
||||
(value: string, message?: string): Assertion;
|
||||
(value: number, message?: string): Assertion;
|
||||
keys: Keys;
|
||||
members: Members;
|
||||
}
|
||||
|
||||
interface Keys {
|
||||
(...keys: string[]): Expect;
|
||||
(keys: any[]): Expect;
|
||||
}
|
||||
|
||||
interface Members {
|
||||
(set: any[], message?: string): Expect;
|
||||
(...keys: string[]): Assertion;
|
||||
(keys: any[]): Assertion;
|
||||
}
|
||||
|
||||
interface Throw {
|
||||
(): Expect;
|
||||
(expected: string, message?: string): Expect;
|
||||
(expected: RegExp, message?: string): Expect;
|
||||
(constructor: Error, expected?: string, message?: string): Expect;
|
||||
(constructor: Error, expected?: RegExp, message?: string): Expect;
|
||||
(constructor: Function, expected?: string, message?: string): Expect;
|
||||
(constructor: Function, expected?: RegExp, message?: string): Expect;
|
||||
(): Assertion;
|
||||
(expected: string, message?: string): Assertion;
|
||||
(expected: RegExp, message?: string): Assertion;
|
||||
(constructor: Error, expected?: string, message?: string): Assertion;
|
||||
(constructor: Error, expected?: RegExp, message?: string): Assertion;
|
||||
(constructor: Function, expected?: string, message?: string): Assertion;
|
||||
(constructor: Function, expected?: RegExp, message?: string): Assertion;
|
||||
}
|
||||
|
||||
interface Members {
|
||||
(set: any[], message?: string): Assertion;
|
||||
}
|
||||
|
||||
export interface Assert {
|
||||
(express: any, msg?: string):void;
|
||||
/**
|
||||
* @param expression Expression to test for truthiness.
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
(expression: any, message?: string): void;
|
||||
|
||||
fail(actual?: any, expected?: any, msg?: string, operator?: string):void;
|
||||
fail(actual?: any, expected?: any, msg?: string, operator?: string): void;
|
||||
|
||||
ok(val: any, msg?: string):void;
|
||||
notOk(val: any, msg?: string):void;
|
||||
ok(val: any, msg?: string): void;
|
||||
notOk(val: any, msg?: string): void;
|
||||
|
||||
equal(act: any, exp: any, msg?: string):void;
|
||||
notEqual(act: any, exp: any, msg?: string):void;
|
||||
equal(act: any, exp: any, msg?: string): void;
|
||||
notEqual(act: any, exp: any, msg?: string): void;
|
||||
|
||||
strictEqual(act: any, exp: any, msg?: string):void;
|
||||
notStrictEqual(act: any, exp: any, msg?: string):void;
|
||||
strictEqual(act: any, exp: any, msg?: string): void;
|
||||
notStrictEqual(act: any, exp: any, msg?: string): void;
|
||||
|
||||
deepEqual(act: any, exp: any, msg?: string):void;
|
||||
notDeepEqual(act: any, exp: any, msg?: string):void;
|
||||
deepEqual(act: any, exp: any, msg?: string): void;
|
||||
notDeepEqual(act: any, exp: any, msg?: string): void;
|
||||
|
||||
isTrue(val: any, msg?: string):void;
|
||||
isFalse(val: any, msg?: string):void;
|
||||
isTrue(val: any, msg?: string): void;
|
||||
isFalse(val: any, msg?: string): void;
|
||||
|
||||
isNull(val: any, msg?: string):void;
|
||||
isNotNull(val: any, msg?: string):void;
|
||||
isNull(val: any, msg?: string): void;
|
||||
isNotNull(val: any, msg?: string): void;
|
||||
|
||||
isUndefined(val: any, msg?: string):void;
|
||||
isDefined(val: any, msg?: string):void;
|
||||
isUndefined(val: any, msg?: string): void;
|
||||
isDefined(val: any, msg?: string): void;
|
||||
|
||||
isFunction(val: any, msg?: string):void;
|
||||
isNotFunction(val: any, msg?: string):void;
|
||||
isFunction(val: any, msg?: string): void;
|
||||
isNotFunction(val: any, msg?: string): void;
|
||||
|
||||
isObject(val: any, msg?: string):void;
|
||||
isNotObject(val: any, msg?: string):void;
|
||||
isObject(val: any, msg?: string): void;
|
||||
isNotObject(val: any, msg?: string): void;
|
||||
|
||||
isArray(val: any, msg?: string):void;
|
||||
isNotArray(val: any, msg?: string):void;
|
||||
isArray(val: any, msg?: string): void;
|
||||
isNotArray(val: any, msg?: string): void;
|
||||
|
||||
isString(val: any, msg?: string):void;
|
||||
isNotString(val: any, msg?: string):void;
|
||||
isString(val: any, msg?: string): void;
|
||||
isNotString(val: any, msg?: string): void;
|
||||
|
||||
isNumber(val: any, msg?: string):void;
|
||||
isNotNumber(val: any, msg?: string):void;
|
||||
isNumber(val: any, msg?: string): void;
|
||||
isNotNumber(val: any, msg?: string): void;
|
||||
|
||||
isBoolean(val: any, msg?: string):void;
|
||||
isNotBoolean(val: any, msg?: string):void;
|
||||
isBoolean(val: any, msg?: string): void;
|
||||
isNotBoolean(val: any, msg?: string): void;
|
||||
|
||||
typeOf(val: any, type: string, msg?: string):void;
|
||||
notTypeOf(val: any, type: string, msg?: string):void;
|
||||
typeOf(val: any, type: string, msg?: string): void;
|
||||
notTypeOf(val: any, type: string, msg?: string): void;
|
||||
|
||||
instanceOf(val: any, type: Function, msg?: string):void;
|
||||
notInstanceOf(val: any, type: Function, msg?: string):void;
|
||||
instanceOf(val: any, type: Function, msg?: string): void;
|
||||
notInstanceOf(val: any, type: Function, msg?: string): void;
|
||||
|
||||
include(exp: string, inc: any, msg?: string):void;
|
||||
include(exp: any[], inc: any, msg?: string):void;
|
||||
include(exp: string, inc: any, msg?: string): void;
|
||||
include(exp: any[], inc: any, msg?: string): void;
|
||||
|
||||
notInclude(exp: string, inc: any, msg?: string):void;
|
||||
notInclude(exp: any[], inc: any, msg?: string):void;
|
||||
notInclude(exp: string, inc: any, msg?: string): void;
|
||||
notInclude(exp: any[], inc: any, msg?: string): void;
|
||||
|
||||
match(exp: any, re: RegExp, msg?: string):void;
|
||||
notMatch(exp: any, re: RegExp, msg?: string):void;
|
||||
match(exp: any, re: RegExp, msg?: string): void;
|
||||
notMatch(exp: any, re: RegExp, msg?: string): void;
|
||||
|
||||
property(obj: Object, prop: string, msg?: string):void;
|
||||
notProperty(obj: Object, prop: string, msg?: string):void;
|
||||
deepProperty(obj: Object, prop: string, msg?: string):void;
|
||||
notDeepProperty(obj: Object, prop: string, msg?: string):void;
|
||||
property(obj: Object, prop: string, msg?: string): void;
|
||||
notProperty(obj: Object, prop: string, msg?: string): void;
|
||||
deepProperty(obj: Object, prop: string, msg?: string): void;
|
||||
notDeepProperty(obj: Object, prop: string, msg?: string): void;
|
||||
|
||||
propertyVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
propertyNotVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
propertyVal(obj: Object, prop: string, val: any, msg?: string): void;
|
||||
propertyNotVal(obj: Object, prop: string, val: any, msg?: string): void;
|
||||
|
||||
deepPropertyVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string):void;
|
||||
deepPropertyVal(obj: Object, prop: string, val: any, msg?: string): void;
|
||||
deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string): void;
|
||||
|
||||
lengthOf(exp: any, len: number, msg?: string):void;
|
||||
lengthOf(exp: any, len: number, msg?: string): void;
|
||||
//alias frenzy
|
||||
throw(fn: Function, msg?: string):void;
|
||||
throw(fn: Function, regExp: RegExp):void;
|
||||
throw(fn: Function, errType: Function, msg?: string):void;
|
||||
throw(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
throw(fn: Function, msg?: string): void;
|
||||
throw(fn: Function, regExp: RegExp): void;
|
||||
throw(fn: Function, errType: Function, msg?: string): void;
|
||||
throw(fn: Function, errType: Function, regExp: RegExp): void;
|
||||
|
||||
throws(fn: Function, msg?: string):void;
|
||||
throws(fn: Function, regExp: RegExp):void;
|
||||
throws(fn: Function, errType: Function, msg?: string):void;
|
||||
throws(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
throws(fn: Function, msg?: string): void;
|
||||
throws(fn: Function, regExp: RegExp): void;
|
||||
throws(fn: Function, errType: Function, msg?: string): void;
|
||||
throws(fn: Function, errType: Function, regExp: RegExp): void;
|
||||
|
||||
Throw(fn: Function, msg?: string):void;
|
||||
Throw(fn: Function, regExp: RegExp):void;
|
||||
Throw(fn: Function, errType: Function, msg?: string):void;
|
||||
Throw(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
Throw(fn: Function, msg?: string): void;
|
||||
Throw(fn: Function, regExp: RegExp): void;
|
||||
Throw(fn: Function, errType: Function, msg?: string): void;
|
||||
Throw(fn: Function, errType: Function, regExp: RegExp): void;
|
||||
|
||||
doesNotThrow(fn: Function, msg?: string):void;
|
||||
doesNotThrow(fn: Function, regExp: RegExp):void;
|
||||
doesNotThrow(fn: Function, errType: Function, msg?: string):void;
|
||||
doesNotThrow(fn: Function, errType: Function, regExp: RegExp):void;
|
||||
doesNotThrow(fn: Function, msg?: string): void;
|
||||
doesNotThrow(fn: Function, regExp: RegExp): void;
|
||||
doesNotThrow(fn: Function, errType: Function, msg?: string): void;
|
||||
doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void;
|
||||
|
||||
operator(val: any, operator: string, val2: any, msg?: string):void;
|
||||
closeTo(act: number, exp: number, delta: number, msg?: string):void;
|
||||
operator(val: any, operator: string, val2: any, msg?: string): void;
|
||||
closeTo(act: number, exp: number, delta: number, msg?: string): void;
|
||||
|
||||
sameMembers(set1: any[], set2: any[], msg?: string):void;
|
||||
includeMembers(set1: any[], set2: any[], msg?: string):void;
|
||||
sameMembers(set1: any[], set2: any[], msg?: string): void;
|
||||
includeMembers(set1: any[], set2: any[], msg?: string): void;
|
||||
|
||||
ifError(val: any, msg?: string):void;
|
||||
ifError(val: any, msg?: string): void;
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
includeStack: boolean;
|
||||
}
|
||||
|
||||
export class AssertionError {
|
||||
constructor(message: string, _props?: any, ssf?: Function);
|
||||
name: string;
|
||||
message: string;
|
||||
showDiff: boolean;
|
||||
stack: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare var chai: Chai.ChaiStatic;
|
||||
|
||||
declare module "chai" {
|
||||
export = chai;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
/// <reference path="sinon-chai.d.ts" />
|
||||
|
||||
declare var expect: chai.ExpectStatic;
|
||||
|
||||
import chai = require('chai');
|
||||
import sinonChai = require('sinon-chai');
|
||||
|
||||
chai.use(sinonChai);
|
||||
var expect = chai.expect;
|
||||
declare var spy: Sinon.SinonSpy;
|
||||
declare var anotherSpy: Sinon.SinonSpy;
|
||||
declare var context: {};
|
||||
declare var match: RegExp;
|
||||
|
||||
// ReSharper disable WrongExpressionStatement
|
||||
function test() {
|
||||
var spy: Function;
|
||||
var anotherSpy: Function;
|
||||
var context: any;
|
||||
var match: any;
|
||||
|
||||
expect(spy).to.have.been.called;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledTwice;
|
||||
@@ -32,6 +30,10 @@ function test() {
|
||||
expect(spy).to.always.have.been.calledWithMatch(match);
|
||||
expect(spy).to.have.returned(1);
|
||||
expect(spy).to.have.always.returned(1);
|
||||
expect(spy).to.have.thrown(new Error());
|
||||
expect(spy).to.have.thrown(Error);
|
||||
expect(spy).to.have.thrown('an error');
|
||||
expect(spy).to.have.always.thrown(new Error());
|
||||
expect(spy).to.have.always.thrown(Error);
|
||||
expect(spy).to.have.always.thrown('an error');
|
||||
}
|
||||
|
||||
94
sinon-chai/sinon-chai.d.ts
vendored
94
sinon-chai/sinon-chai.d.ts
vendored
@@ -1,34 +1,84 @@
|
||||
// Type definitions for sinon-chai 2.4.0
|
||||
// Type definitions for sinon-chai 2.7.0
|
||||
// Project: https://github.com/domenic/sinon-chai
|
||||
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
|
||||
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, Jed Mao <https://github.com/jedmao/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
/// <reference path="../sinon/sinon.d.ts" />
|
||||
|
||||
declare module chai {
|
||||
interface Expect {
|
||||
called: Expect;
|
||||
calledOnce: Expect;
|
||||
calledTwice: Expect;
|
||||
calledThrice: Expect;
|
||||
callCount(count: number): Expect;
|
||||
calledBefore(spy: Function): Expect;
|
||||
calledAfter(spy: Function): Expect;
|
||||
calledWithNew: Expect;
|
||||
calledOn(context: any): Expect;
|
||||
calledWith(...args: any[]): Expect;
|
||||
calledWithExactly(...args: any[]): Expect;
|
||||
calledWithMatch(...args: any[]): Expect;
|
||||
returned(returnVal: any): Expect;
|
||||
thrown(errorObjOrErrorTypeStringOrNothing: any): Expect;
|
||||
}
|
||||
declare module Chai {
|
||||
|
||||
interface LanguageChains {
|
||||
always: Expect;
|
||||
always: Assertion;
|
||||
}
|
||||
|
||||
interface Assertion {
|
||||
/**
|
||||
* true if the spy was called at least once.
|
||||
*/
|
||||
called: Assertion;
|
||||
/**
|
||||
* @param count The number of recorded calls.
|
||||
*/
|
||||
callCount(count: number): Assertion;
|
||||
/**
|
||||
* true if the spy was called exactly once.
|
||||
*/
|
||||
calledOnce: Assertion;
|
||||
/**
|
||||
* true if the spy was called exactly twice.
|
||||
*/
|
||||
calledTwice: Assertion;
|
||||
/**
|
||||
* true if the spy was called exactly thrice.
|
||||
*/
|
||||
calledThrice: Assertion;
|
||||
/**
|
||||
* Returns true if the spy was called before anotherSpy.
|
||||
*/
|
||||
calledBefore(anotherSpy: Sinon.SinonSpy): Assertion;
|
||||
/**
|
||||
* Returns true if the spy was called after anotherSpy.
|
||||
*/
|
||||
calledAfter(anotherSpy: Sinon.SinonSpy): Assertion;
|
||||
/**
|
||||
* Returns true if spy/stub was called with the new operator. Beware that
|
||||
* this is inferred based on the value of the this object and the spy
|
||||
* function's prototype, so it may give false positives if you actively
|
||||
* return the right kind of object.
|
||||
*/
|
||||
calledWithNew: Assertion;
|
||||
/**
|
||||
* Returns true if context was this for this call.
|
||||
*/
|
||||
calledOn(context: any): Assertion;
|
||||
/**
|
||||
* Returns true if call received provided arguments (and possibly others).
|
||||
*/
|
||||
calledWith(...args: any[]): Assertion;
|
||||
/**
|
||||
* Returns true if call received provided arguments and no others.
|
||||
*/
|
||||
calledWithExactly(...args: any[]): Assertion;
|
||||
/**
|
||||
* Returns true if call received matching arguments (and possibly others).
|
||||
* This behaves the same as spyCall.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
|
||||
*/
|
||||
calledWithMatch(...args: any[]): Assertion;
|
||||
/**
|
||||
* Returns true if spy returned the provided value at least once. Uses
|
||||
* deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj))
|
||||
* for strict comparison (see matchers).
|
||||
*/
|
||||
returned(obj: any): Assertion;
|
||||
/**
|
||||
* Returns true if spy threw the provided exception object at least once.
|
||||
*/
|
||||
thrown(obj?: Error|typeof Error|string): Assertion;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "sinon-chai" {
|
||||
function exports(_chai: typeof chai, utils: any): void;
|
||||
export = exports;
|
||||
function sinonChai(chai: any, utils: any): void;
|
||||
export = sinonChai;
|
||||
}
|
||||
|
||||
@@ -1,95 +1,91 @@
|
||||
/// <reference path="sinon.d.ts" />
|
||||
|
||||
function once(fn: Function) {
|
||||
var returnValue: any, called = false;
|
||||
return function () {
|
||||
if (!called) {
|
||||
called = true;
|
||||
returnValue = fn.apply(this, arguments);
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
var returnValue: any, called = false;
|
||||
return function () {
|
||||
if (!called) {
|
||||
called = true;
|
||||
returnValue = fn.apply(this, arguments);
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
}
|
||||
|
||||
function testOne() {
|
||||
var callback = sinon.spy();
|
||||
var proxy = once(callback);
|
||||
proxy();
|
||||
if (callback.calledOnce) { console.log("test1 calledOnce success"); } else { console.log("test1 calledOnce failure"); }
|
||||
var callback = sinon.spy();
|
||||
var proxy = once(callback);
|
||||
proxy();
|
||||
if (callback.calledOnce) { console.log("test1 calledOnce success"); } else { console.log("test1 calledOnce failure"); }
|
||||
}
|
||||
|
||||
function testTwo() {
|
||||
var callback = sinon.spy(() => {});
|
||||
var proxy = once(callback);
|
||||
proxy();
|
||||
proxy();
|
||||
if (callback.calledOnce) { console.log("test2 calledOnce success"); } else { console.log("test2 calledOnce failure"); }
|
||||
var callback = sinon.spy(() => {});
|
||||
var proxy = once(callback);
|
||||
proxy();
|
||||
proxy();
|
||||
if (callback.calledOnce) { console.log("test2 calledOnce success"); } else { console.log("test2 calledOnce failure"); }
|
||||
}
|
||||
|
||||
function testThree() {
|
||||
var obj = { thisObj: true };
|
||||
var callback = sinon.spy({}, "method");
|
||||
var proxy = once(callback);
|
||||
proxy.call(obj, callback, 1, 2, 3);
|
||||
if (callback.calledOn(obj)) { console.log("test3 calledOn success"); } else { console.log("test3 calledOn failure"); }
|
||||
if (callback.calledWith(callback, 1, 2, 3)) { console.log("test3 calledWith success"); } else { console.log("test3 calledWith failure"); }
|
||||
var obj = { thisObj: true };
|
||||
var callback = sinon.spy({}, "method");
|
||||
var proxy = once(callback);
|
||||
proxy.call(obj, callback, 1, 2, 3);
|
||||
if (callback.calledOn(obj)) { console.log("test3 calledOn success"); } else { console.log("test3 calledOn failure"); }
|
||||
if (callback.calledWith(callback, 1, 2, 3)) { console.log("test3 calledWith success"); } else { console.log("test3 calledWith failure"); }
|
||||
}
|
||||
|
||||
function testFour() {
|
||||
var obj = { thisObj: true };
|
||||
var callback = sinon.stub().returns(42);
|
||||
var proxy = once(callback);
|
||||
var val = proxy.apply(callback, [1, 2, 3]);
|
||||
if (val == 42) { console.log("test4 returns success"); } else { console.log("test4 returns failure"); }
|
||||
var callback = sinon.stub().returns(42);
|
||||
var proxy = once(callback);
|
||||
var val = proxy.apply(callback, [1, 2, 3]);
|
||||
if (val === 42) { console.log("test4 returns success"); } else { console.log("test4 returns failure"); }
|
||||
}
|
||||
|
||||
function testFive() {
|
||||
var obj = { thisObj: true };
|
||||
var callback = sinon.stub().returnsArg(1);
|
||||
var proxy = once(callback);
|
||||
var val = proxy.apply(callback, [1, 2, 3]);
|
||||
if (val == 2) { console.log("test5 returnsArg success"); } else { console.log("test5 returnsArg failure"); }
|
||||
var callback = sinon.stub().returnsArg(1);
|
||||
var proxy = once(callback);
|
||||
var val = proxy.apply(callback, [1, 2, 3]);
|
||||
if (val === 2) { console.log("test5 returnsArg success"); } else { console.log("test5 returnsArg failure"); }
|
||||
}
|
||||
|
||||
var objectUnderTest: any = {
|
||||
process: function (obj: any) {
|
||||
// It doesn't really matter what's here because the stub is going to replace this function
|
||||
var dummy = true;
|
||||
if (dummy) { return obj.success(99); } else { obj.failure(99); }
|
||||
}
|
||||
process: (obj: any) => {
|
||||
// It doesn't really matter what's here because the stub is going to replace this function
|
||||
return obj.success(99);
|
||||
}
|
||||
};
|
||||
|
||||
function testSix() {
|
||||
var obj = { thisObj: true };
|
||||
var stub = sinon.stub(objectUnderTest, "process").yieldsTo("success");
|
||||
var val = objectUnderTest.process({
|
||||
success: function () { console.log("test6 yieldsTo success"); },
|
||||
failure: function () { console.log("test6 yieldsTo failure"); }
|
||||
});
|
||||
stub.restore();
|
||||
var stub = sinon.stub(objectUnderTest, "process").yieldsTo("success");
|
||||
objectUnderTest.process({
|
||||
success: () => { console.log("test6 yieldsTo success"); },
|
||||
failure: () => { console.log("test6 yieldsTo failure"); }
|
||||
});
|
||||
stub.restore();
|
||||
}
|
||||
|
||||
function testSeven() {
|
||||
var obj = { functionToTest : function () { } };
|
||||
var mockObj = sinon.mock(obj);
|
||||
obj.functionToTest();
|
||||
mockObj.expects('functionToTest').once();
|
||||
var obj = { functionToTest : () => { } };
|
||||
var mockObj = sinon.mock(obj);
|
||||
obj.functionToTest();
|
||||
mockObj.expects('functionToTest').once();
|
||||
}
|
||||
|
||||
function testEight() {
|
||||
var combinedMatcher = sinon.match.typeOf("object").and(sinon.match.has("pages"));
|
||||
sinon.match.typeOf("object").and(sinon.match.has("pages"));
|
||||
}
|
||||
|
||||
function testSandbox() {
|
||||
var sandbox = sinon.sandbox.create();
|
||||
if (sandbox.spy().called) {
|
||||
sandbox.stub(objectUnderTest, "process").yieldsTo("success");
|
||||
sandbox.mock(objectUnderTest).expects("process").once();
|
||||
}
|
||||
sandbox.useFakeTimers();
|
||||
sandbox.useFakeXMLHttpRequest();
|
||||
sandbox.useFakeServer();
|
||||
sandbox.restore();
|
||||
var sandbox = sinon.sandbox.create();
|
||||
if (sandbox.spy().called) {
|
||||
sandbox.stub(objectUnderTest, "process").yieldsTo("success");
|
||||
sandbox.mock(objectUnderTest).expects("process").once();
|
||||
}
|
||||
sandbox.useFakeTimers();
|
||||
sandbox.useFakeXMLHttpRequest();
|
||||
sandbox.useFakeServer();
|
||||
sandbox.restore();
|
||||
}
|
||||
|
||||
testOne();
|
||||
|
||||
814
sinon/sinon.d.ts
vendored
814
sinon/sinon.d.ts
vendored
@@ -3,415 +3,417 @@
|
||||
// Definitions by: William Sears <https://github.com/mrbigdog2u>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface SinonSpyCallApi {
|
||||
// Properties
|
||||
thisValue: any;
|
||||
args: any[];
|
||||
exception: any;
|
||||
returnValue: any;
|
||||
declare module Sinon {
|
||||
interface SinonSpyCallApi {
|
||||
// Properties
|
||||
thisValue: any;
|
||||
args: any[];
|
||||
exception: any;
|
||||
returnValue: any;
|
||||
|
||||
// Methods
|
||||
calledOn(obj: any): boolean;
|
||||
calledWith(...args: any[]): boolean;
|
||||
calledWithExactly(...args: any[]): boolean;
|
||||
calledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
notCalledWith(...args: any[]): boolean;
|
||||
notCalledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
returned(value: any): boolean;
|
||||
threw(): boolean;
|
||||
threw(type: string): boolean;
|
||||
threw(obj: any): boolean;
|
||||
callArg(pos: number): void;
|
||||
callArgOn(pos: number, obj: any, ...args: any[]): void;
|
||||
callArgWith(pos: number, ...args: any[]): void;
|
||||
callArgOnWith(pos: number, obj: any, ...args: any[]): void;
|
||||
yield(...args: any[]): void;
|
||||
yieldOn(obj: any, ...args: any[]): void;
|
||||
yieldTo(property: string, ...args: any[]): void;
|
||||
yieldToOn(property: string, obj: any, ...args: any[]): void;
|
||||
// Methods
|
||||
calledOn(obj: any): boolean;
|
||||
calledWith(...args: any[]): boolean;
|
||||
calledWithExactly(...args: any[]): boolean;
|
||||
calledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
notCalledWith(...args: any[]): boolean;
|
||||
notCalledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
returned(value: any): boolean;
|
||||
threw(): boolean;
|
||||
threw(type: string): boolean;
|
||||
threw(obj: any): boolean;
|
||||
callArg(pos: number): void;
|
||||
callArgOn(pos: number, obj: any, ...args: any[]): void;
|
||||
callArgWith(pos: number, ...args: any[]): void;
|
||||
callArgOnWith(pos: number, obj: any, ...args: any[]): void;
|
||||
yield(...args: any[]): void;
|
||||
yieldOn(obj: any, ...args: any[]): void;
|
||||
yieldTo(property: string, ...args: any[]): void;
|
||||
yieldToOn(property: string, obj: any, ...args: any[]): void;
|
||||
}
|
||||
|
||||
interface SinonSpyCall extends SinonSpyCallApi {
|
||||
calledBefore(call: SinonSpyCall): boolean;
|
||||
calledAfter(call: SinonSpyCall): boolean;
|
||||
calledWithNew(call: SinonSpyCall): boolean;
|
||||
}
|
||||
|
||||
interface SinonSpy extends SinonSpyCallApi {
|
||||
// Properties
|
||||
callCount: number;
|
||||
called: boolean;
|
||||
notCalled: boolean;
|
||||
calledOnce: boolean;
|
||||
calledTwice: boolean;
|
||||
calledThrice: boolean;
|
||||
firstCall: SinonSpyCall;
|
||||
secondCall: SinonSpyCall;
|
||||
thirdCall: SinonSpyCall;
|
||||
lastCall: SinonSpyCall;
|
||||
thisValues: any[];
|
||||
args: any[][];
|
||||
exceptions: any[];
|
||||
returnValues: any[];
|
||||
|
||||
// Methods
|
||||
(...args: any[]): any;
|
||||
calledBefore(anotherSpy: SinonSpy): boolean;
|
||||
calledAfter(anotherSpy: SinonSpy): boolean;
|
||||
calledWithNew(spy: SinonSpy): boolean;
|
||||
withArgs(...args: any[]): SinonSpy;
|
||||
alwaysCalledOn(obj: any): boolean;
|
||||
alwaysCalledWith(...args: any[]): boolean;
|
||||
alwaysCalledWithExactly(...args: any[]): boolean;
|
||||
alwaysCalledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
neverCalledWith(...args: any[]): boolean;
|
||||
neverCalledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
alwaysThrew(): boolean;
|
||||
alwaysThrew(type: string): boolean;
|
||||
alwaysThrew(obj: any): boolean;
|
||||
alwaysReturned(): boolean;
|
||||
invokeCallback(...args: any[]): void;
|
||||
getCall(n: number): SinonSpyCall;
|
||||
reset(): void;
|
||||
printf(format: string, ...args: any[]): string;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonSpyStatic {
|
||||
(): SinonSpy;
|
||||
(func: any): SinonSpy;
|
||||
(obj: any, method: string): SinonSpy;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
spy: SinonSpyStatic;
|
||||
}
|
||||
|
||||
interface SinonStub extends SinonSpy {
|
||||
resetBehavior(): void;
|
||||
returns(obj: any): SinonStub;
|
||||
returnsArg(index: number): SinonStub;
|
||||
throws(type?: string): SinonStub;
|
||||
throws(obj: any): SinonStub;
|
||||
callsArg(index: number): SinonStub;
|
||||
callsArgOn(index: number, context: any): SinonStub;
|
||||
callsArgWith(index: number, ...args: any[]): SinonStub;
|
||||
callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub;
|
||||
callsArgAsync(index: number): SinonStub;
|
||||
callsArgOnAsync(index: number, context: any): SinonStub;
|
||||
callsArgWithAsync(index: number, ...args: any[]): SinonStub;
|
||||
callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub;
|
||||
onCall(n: number): SinonStub;
|
||||
onFirstCall(): SinonStub;
|
||||
onSecondCall(): SinonStub;
|
||||
onThirdCall(): SinonStub;
|
||||
yields(...args: any[]): SinonStub;
|
||||
yieldsOn(context: any, ...args: any[]): SinonStub;
|
||||
yieldsTo(property: string, ...args: any[]): SinonStub;
|
||||
yieldsToOn(property: string, context: any, ...args: any[]): SinonStub;
|
||||
yieldsAsync(...args: any[]): SinonStub;
|
||||
yieldsOnAsync(context: any, ...args: any[]): SinonStub;
|
||||
yieldsToAsync(property: string, ...args: any[]): SinonStub;
|
||||
yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub;
|
||||
withArgs(...args: any[]): SinonStub;
|
||||
}
|
||||
|
||||
interface SinonStubStatic {
|
||||
(): SinonStub;
|
||||
(obj: any): SinonStub;
|
||||
(obj: any, method: string): SinonStub;
|
||||
(obj: any, method: string, func: any): SinonStub;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
stub: SinonStubStatic;
|
||||
}
|
||||
|
||||
interface SinonExpectation extends SinonStub {
|
||||
atLeast(n: number): SinonExpectation;
|
||||
atMost(n: number): SinonExpectation;
|
||||
never(): SinonExpectation;
|
||||
once(): SinonExpectation;
|
||||
twice(): SinonExpectation;
|
||||
thrice(): SinonExpectation;
|
||||
exactly(n: number): SinonExpectation;
|
||||
withArgs(...args: any[]): SinonExpectation;
|
||||
withExactArgs(...args: any[]): SinonExpectation;
|
||||
on(obj: any): SinonExpectation;
|
||||
verify(): SinonExpectation;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonExpectationStatic {
|
||||
create(methodName?: string): SinonExpectation;
|
||||
}
|
||||
|
||||
interface SinonMock {
|
||||
expects(method: string): SinonExpectation;
|
||||
restore(): void;
|
||||
verify(): void;
|
||||
}
|
||||
|
||||
interface SinonMockStatic {
|
||||
(): SinonExpectation;
|
||||
(obj: any): SinonMock;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
expectation: SinonExpectationStatic;
|
||||
mock: SinonMockStatic;
|
||||
}
|
||||
|
||||
interface SinonFakeTimers {
|
||||
now: number;
|
||||
create(now: number): SinonFakeTimers;
|
||||
setTimeout(callback: (...args: any[]) => void, timeout: number, ...args: any[]): number;
|
||||
clearTimeout(id: number): void;
|
||||
setInterval(callback: (...args: any[]) => void, timeout: number, ...args: any[]): number;
|
||||
clearInterval(id: number): void;
|
||||
tick(ms: number): number;
|
||||
reset(): void;
|
||||
Date(): Date;
|
||||
Date(year: number): Date;
|
||||
Date(year: number, month: number): Date;
|
||||
Date(year: number, month: number, day: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number, minute: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number, minute: number, second: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number, minute: number, second: number, ms: number): Date;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonFakeTimersStatic {
|
||||
(): SinonFakeTimers;
|
||||
(...timers: string[]): SinonFakeTimers;
|
||||
(now: number, ...timers: string[]): SinonFakeTimers;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
useFakeTimers: SinonFakeTimersStatic;
|
||||
clock: SinonFakeTimers;
|
||||
}
|
||||
|
||||
interface SinonFakeUploadProgress {
|
||||
eventListeners: {
|
||||
progress: any[];
|
||||
load: any[];
|
||||
abort: any[];
|
||||
error: any[];
|
||||
};
|
||||
|
||||
addEventListener(event: string, listener: (e: Event) => any): void;
|
||||
removeEventListener(event: string, listener: (e: Event) => any): void;
|
||||
dispatchEvent(event: Event): void;
|
||||
}
|
||||
|
||||
interface SinonFakeXMLHttpRequest {
|
||||
// Properties
|
||||
onCreate: (xhr: SinonFakeXMLHttpRequest) => void;
|
||||
url: string;
|
||||
method: string;
|
||||
requestHeaders: any;
|
||||
requestBody: string;
|
||||
status: number;
|
||||
statusText: string;
|
||||
async: boolean;
|
||||
username: string;
|
||||
password: string;
|
||||
withCredentials: boolean;
|
||||
upload: SinonFakeUploadProgress;
|
||||
responseXML: Document;
|
||||
getResponseHeader(header: string): string;
|
||||
getAllResponseHeaders(): any;
|
||||
|
||||
// Methods
|
||||
restore(): void;
|
||||
useFilters: boolean;
|
||||
addFilter(filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean): void;
|
||||
setResponseHeaders(headers: any): void;
|
||||
setResponseBody(body: string): void;
|
||||
respond(status: number, headers: any, body: string): void;
|
||||
autoRespond(ms: number): void;
|
||||
}
|
||||
|
||||
interface SinonFakeXMLHttpRequestStatic {
|
||||
(): SinonFakeXMLHttpRequest;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic;
|
||||
FakeXMLHttpRequest: SinonFakeXMLHttpRequest;
|
||||
}
|
||||
|
||||
interface SinonFakeServer {
|
||||
// Properties
|
||||
autoRespond: boolean;
|
||||
autoRespondAfter: number;
|
||||
fakeHTTPMethods: boolean;
|
||||
getHTTPMethod: (request: SinonFakeXMLHttpRequest) => string;
|
||||
requests: SinonFakeXMLHttpRequest[];
|
||||
|
||||
// Methods
|
||||
respondWith(body: string): void;
|
||||
respondWith(response: any[]): void;
|
||||
respondWith(fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
|
||||
respondWith(url: string, body: string): void;
|
||||
respondWith(url: string, response: any[]): void;
|
||||
respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
|
||||
respondWith(method: string, url: string, body: string): void;
|
||||
respondWith(method: string, url: string, response: any[]): void;
|
||||
respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
|
||||
respondWith(url: RegExp, body: string): void;
|
||||
respondWith(url: RegExp, response: any[]): void;
|
||||
respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
|
||||
respondWith(method: string, url: RegExp, body: string): void;
|
||||
respondWith(method: string, url: RegExp, response: any[]): void;
|
||||
respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
|
||||
respond(): void;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonFakeServerStatic {
|
||||
create(): SinonFakeServer;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
fakeServer: SinonFakeServerStatic;
|
||||
fakeServerWithClock: SinonFakeServerStatic;
|
||||
}
|
||||
|
||||
interface SinonExposeOptions {
|
||||
prefix?: string;
|
||||
includeFail?: boolean;
|
||||
}
|
||||
|
||||
interface SinonAssert {
|
||||
// Properties
|
||||
failException: string;
|
||||
fail: (message?: string) => void; // Overridable
|
||||
pass: (assertion: any) => void; // Overridable
|
||||
|
||||
// Methods
|
||||
notCalled(spy: SinonSpy): void;
|
||||
called(spy: SinonSpy): void;
|
||||
calledOnce(spy: SinonSpy): void;
|
||||
calledTwice(spy: SinonSpy): void;
|
||||
calledThrice(spy: SinonSpy): void;
|
||||
callCount(spy: SinonSpy, count: number): void;
|
||||
callOrder(...spies: SinonSpy[]): void;
|
||||
calledOn(spy: SinonSpy, obj: any): void;
|
||||
alwaysCalledOn(spy: SinonSpy, obj: any): void;
|
||||
calledWith(spy: SinonSpy, ...args: any[]): void;
|
||||
alwaysCalledWith(spy: SinonSpy, ...args: any[]): void;
|
||||
neverCalledWith(spy: SinonSpy, ...args: any[]): void;
|
||||
calledWithExactly(spy: SinonSpy, ...args: any[]): void;
|
||||
alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void;
|
||||
calledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void;
|
||||
alwaysCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void;
|
||||
neverCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void;
|
||||
threw(spy: SinonSpy): void;
|
||||
threw(spy: SinonSpy, exception: string): void;
|
||||
threw(spy: SinonSpy, exception: any): void;
|
||||
alwaysThrew(spy: SinonSpy): void;
|
||||
alwaysThrew(spy: SinonSpy, exception: string): void;
|
||||
alwaysThrew(spy: SinonSpy, exception: any): void;
|
||||
expose(obj: any, options?: SinonExposeOptions): void;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
assert: SinonAssert;
|
||||
}
|
||||
|
||||
interface SinonMatcher {
|
||||
and(expr: SinonMatcher): SinonMatcher;
|
||||
or(expr: SinonMatcher): SinonMatcher;
|
||||
}
|
||||
|
||||
interface SinonMatch {
|
||||
(value: number): SinonMatcher;
|
||||
(value: string): SinonMatcher;
|
||||
(expr: RegExp): SinonMatcher;
|
||||
(obj: any): SinonMatcher;
|
||||
(callback: (value: any) => boolean): SinonMatcher;
|
||||
any: SinonMatcher;
|
||||
defined: SinonMatcher;
|
||||
truthy: SinonMatcher;
|
||||
falsy: SinonMatcher;
|
||||
bool: SinonMatcher;
|
||||
number: SinonMatcher;
|
||||
string: SinonMatcher;
|
||||
object: SinonMatcher;
|
||||
func: SinonMatcher;
|
||||
array: SinonMatcher;
|
||||
regexp: SinonMatcher;
|
||||
date: SinonMatcher;
|
||||
same(obj: any): SinonMatcher;
|
||||
typeOf(type: string): SinonMatcher;
|
||||
instanceOf(type: any): SinonMatcher;
|
||||
has(property: string, expect?: any): SinonMatcher;
|
||||
hasOwn(property: string, expect?: any): SinonMatcher;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
match: SinonMatch;
|
||||
}
|
||||
|
||||
interface SinonSandboxConfig {
|
||||
injectInto?: any;
|
||||
properties?: string[];
|
||||
useFakeTimers?: any;
|
||||
useFakeServer?: any;
|
||||
}
|
||||
|
||||
interface SinonSandbox {
|
||||
clock: SinonFakeTimers;
|
||||
requests: SinonFakeXMLHttpRequest;
|
||||
server: SinonFakeServer;
|
||||
spy: SinonSpyStatic;
|
||||
stub: SinonStubStatic;
|
||||
mock: SinonMockStatic;
|
||||
useFakeTimers: SinonFakeTimersStatic;
|
||||
useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic;
|
||||
useFakeServer(): SinonFakeServer;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonSandboxStatic {
|
||||
create(): SinonSandbox;
|
||||
create(config: SinonSandboxConfig): SinonSandbox;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
sandbox: SinonSandboxStatic;
|
||||
}
|
||||
|
||||
interface SinonTestConfig {
|
||||
injectIntoThis?: boolean;
|
||||
injectInto?: any;
|
||||
properties?: string[];
|
||||
useFakeTimers?: boolean;
|
||||
useFakeServer?: boolean;
|
||||
}
|
||||
|
||||
interface SinonTestWrapper extends SinonSandbox {
|
||||
(...args: any[]): any;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
config: SinonTestConfig;
|
||||
test(fn: (...args: any[]) => any): SinonTestWrapper;
|
||||
testCase(tests: any): any;
|
||||
}
|
||||
|
||||
// Utility overridables
|
||||
interface SinonStatic {
|
||||
createStubInstance(constructor: any): SinonStub;
|
||||
format(obj: any): string;
|
||||
log(message: string): void;
|
||||
restore(object: any): void;
|
||||
}
|
||||
}
|
||||
|
||||
interface SinonSpyCall extends SinonSpyCallApi {
|
||||
calledBefore(call: SinonSpyCall): boolean;
|
||||
calledAfter(call: SinonSpyCall): boolean;
|
||||
calledWithNew(call: SinonSpyCall): boolean;
|
||||
}
|
||||
|
||||
interface SinonSpy extends SinonSpyCallApi {
|
||||
// Properties
|
||||
callCount: number;
|
||||
called: boolean;
|
||||
notCalled: boolean;
|
||||
calledOnce: boolean;
|
||||
calledTwice: boolean;
|
||||
calledThrice: boolean;
|
||||
firstCall: SinonSpyCall;
|
||||
secondCall: SinonSpyCall;
|
||||
thirdCall: SinonSpyCall;
|
||||
lastCall: SinonSpyCall;
|
||||
thisValues: any[];
|
||||
args: any[][];
|
||||
exceptions: any[];
|
||||
returnValues: any[];
|
||||
|
||||
// Methods
|
||||
(...args: any[]): any;
|
||||
calledBefore(anotherSpy: SinonSpy): boolean;
|
||||
calledAfter(anotherSpy: SinonSpy): boolean;
|
||||
calledWithNew(spy: SinonSpy): boolean;
|
||||
withArgs(...args: any[]): SinonSpy;
|
||||
alwaysCalledOn(obj: any): boolean;
|
||||
alwaysCalledWith(...args: any[]): boolean;
|
||||
alwaysCalledWithExactly(...args: any[]): boolean;
|
||||
alwaysCalledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
neverCalledWith(...args: any[]): boolean;
|
||||
neverCalledWithMatch(...args: SinonMatcher[]): boolean;
|
||||
alwaysThrew(): boolean;
|
||||
alwaysThrew(type: string): boolean;
|
||||
alwaysThrew(obj: any): boolean;
|
||||
alwaysReturned(): boolean;
|
||||
invokeCallback(...args: any[]): void;
|
||||
getCall(n: number): SinonSpyCall;
|
||||
reset(): void;
|
||||
printf(format: string, ...args: any[]): string;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonSpyStatic {
|
||||
(): SinonSpy;
|
||||
(func: any): SinonSpy;
|
||||
(obj: any, method: string): SinonSpy;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
spy: SinonSpyStatic;
|
||||
}
|
||||
|
||||
interface SinonStub extends SinonSpy {
|
||||
resetBehavior(): void;
|
||||
returns(obj: any): SinonStub;
|
||||
returnsArg(index: number): SinonStub;
|
||||
throws(type?: string): SinonStub;
|
||||
throws(obj: any): SinonStub;
|
||||
callsArg(index: number): SinonStub;
|
||||
callsArgOn(index: number, context: any): SinonStub;
|
||||
callsArgWith(index: number, ...args: any[]): SinonStub;
|
||||
callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub;
|
||||
callsArgAsync(index: number): SinonStub;
|
||||
callsArgOnAsync(index: number, context: any): SinonStub;
|
||||
callsArgWithAsync(index: number, ...args: any[]): SinonStub;
|
||||
callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub;
|
||||
onCall(n: number): SinonStub;
|
||||
onFirstCall(): SinonStub;
|
||||
onSecondCall(): SinonStub;
|
||||
onThirdCall(): SinonStub;
|
||||
yields(...args: any[]): SinonStub;
|
||||
yieldsOn(context: any, ...args: any[]): SinonStub;
|
||||
yieldsTo(property: string, ...args: any[]): SinonStub;
|
||||
yieldsToOn(property: string, context: any, ...args: any[]): SinonStub;
|
||||
yieldsAsync(...args: any[]): SinonStub;
|
||||
yieldsOnAsync(context: any, ...args: any[]): SinonStub;
|
||||
yieldsToAsync(property: string, ...args: any[]): SinonStub;
|
||||
yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub;
|
||||
withArgs(...args: any[]): SinonStub;
|
||||
}
|
||||
|
||||
interface SinonStubStatic {
|
||||
(): SinonStub;
|
||||
(obj: any): SinonStub;
|
||||
(obj: any, method: string): SinonStub;
|
||||
(obj: any, method: string, func: any): SinonStub;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
stub: SinonStubStatic;
|
||||
}
|
||||
|
||||
interface SinonExpectation extends SinonStub {
|
||||
atLeast(n: number): SinonExpectation;
|
||||
atMost(n: number): SinonExpectation;
|
||||
never(): SinonExpectation;
|
||||
once(): SinonExpectation;
|
||||
twice(): SinonExpectation;
|
||||
thrice(): SinonExpectation;
|
||||
exactly(n: number): SinonExpectation;
|
||||
withArgs(...args: any[]): SinonExpectation;
|
||||
withExactArgs(...args: any[]): SinonExpectation;
|
||||
on(obj: any): SinonExpectation;
|
||||
verify(): SinonExpectation;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonExpectationStatic {
|
||||
create(methodName?: string): SinonExpectation;
|
||||
}
|
||||
|
||||
interface SinonMock {
|
||||
expects(method: string): SinonExpectation;
|
||||
restore(): void;
|
||||
verify(): void;
|
||||
}
|
||||
|
||||
interface SinonMockStatic {
|
||||
(): SinonExpectation;
|
||||
(obj: any): SinonMock;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
expectation: SinonExpectationStatic;
|
||||
mock: SinonMockStatic;
|
||||
}
|
||||
|
||||
interface SinonFakeTimers {
|
||||
now: number;
|
||||
create(now: number): SinonFakeTimers;
|
||||
setTimeout(callback: (...args: any[]) => void , timeout: number, ...args: any[]): number;
|
||||
clearTimeout(id: number): void;
|
||||
setInterval(callback: (...args: any[]) => void , timeout: number, ...args: any[]): number;
|
||||
clearInterval(id: number): void;
|
||||
tick(ms: number): number;
|
||||
reset(): void;
|
||||
Date(): Date;
|
||||
Date(year: number): Date;
|
||||
Date(year: number, month: number): Date;
|
||||
Date(year: number, month: number, day: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number, minute: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number, minute: number, second: number): Date;
|
||||
Date(year: number, month: number, day: number, hour: number, minute: number, second: number, ms: number): Date;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonFakeTimersStatic {
|
||||
(): SinonFakeTimers;
|
||||
(...timers: string[]): SinonFakeTimers;
|
||||
(now: number, ...timers: string[]): SinonFakeTimers;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
useFakeTimers: SinonFakeTimersStatic;
|
||||
clock: SinonFakeTimers;
|
||||
}
|
||||
|
||||
interface SinonFakeUploadProgress {
|
||||
eventListeners: {
|
||||
progress: any[];
|
||||
load: any[];
|
||||
abort: any[];
|
||||
error: any[];
|
||||
};
|
||||
|
||||
addEventListener(event: string, listener: (e: Event) => any): void;
|
||||
removeEventListener(event: string, listener: (e: Event) => any): void;
|
||||
dispatchEvent(event: Event): void;
|
||||
}
|
||||
|
||||
interface SinonFakeXMLHttpRequest {
|
||||
// Properties
|
||||
onCreate: (xhr: SinonFakeXMLHttpRequest) => void;
|
||||
url: string;
|
||||
method: string;
|
||||
requestHeaders: any;
|
||||
requestBody: string;
|
||||
status: number;
|
||||
statusText: string;
|
||||
async: boolean;
|
||||
username: string;
|
||||
password: string;
|
||||
withCredentials: boolean;
|
||||
upload: SinonFakeUploadProgress;
|
||||
responseXML: Document;
|
||||
getResponseHeader(header: string): string;
|
||||
getAllResponseHeaders(): any;
|
||||
|
||||
// Methods
|
||||
restore(): void;
|
||||
useFilters: boolean;
|
||||
addFilter(filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean): void;
|
||||
setResponseHeaders(headers: any): void;
|
||||
setResponseBody(body: string): void;
|
||||
respond(status: number, headers: any, body: string): void;
|
||||
autoRespond(ms: number): void;
|
||||
}
|
||||
|
||||
interface SinonFakeXMLHttpRequestStatic {
|
||||
(): SinonFakeXMLHttpRequest;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic;
|
||||
FakeXMLHttpRequest: SinonFakeXMLHttpRequest;
|
||||
}
|
||||
|
||||
interface SinonFakeServer {
|
||||
// Properties
|
||||
autoRespond: boolean;
|
||||
autoRespondAfter: number;
|
||||
fakeHTTPMethods: boolean;
|
||||
getHTTPMethod: (request: SinonFakeXMLHttpRequest) => string;
|
||||
requests: SinonFakeXMLHttpRequest[];
|
||||
|
||||
// Methods
|
||||
respondWith(body: string): void;
|
||||
respondWith(response: any[]): void;
|
||||
respondWith(fn: (xhr: SinonFakeXMLHttpRequest) => void ): void;
|
||||
respondWith(url: string, body: string): void;
|
||||
respondWith(url: string, response: any[]): void;
|
||||
respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void;
|
||||
respondWith(method: string, url: string, body: string): void;
|
||||
respondWith(method: string, url: string, response: any[]): void;
|
||||
respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void;
|
||||
respondWith(url: RegExp, body: string): void;
|
||||
respondWith(url: RegExp, response: any[]): void;
|
||||
respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void;
|
||||
respondWith(method: string, url: RegExp, body: string): void;
|
||||
respondWith(method: string, url: RegExp, response: any[]): void;
|
||||
respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void;
|
||||
respond(): void;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonFakeServerStatic {
|
||||
create(): SinonFakeServer;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
fakeServer: SinonFakeServerStatic;
|
||||
fakeServerWithClock: SinonFakeServerStatic;
|
||||
}
|
||||
|
||||
interface SinonExposeOptions {
|
||||
prefix?: string;
|
||||
includeFail?: boolean;
|
||||
}
|
||||
|
||||
interface SinonAssert {
|
||||
// Properties
|
||||
failException: string;
|
||||
fail: (message?: string) => void; // Overridable
|
||||
pass: (assertion: any) => void; // Overridable
|
||||
|
||||
// Methods
|
||||
notCalled(spy: SinonSpy): void;
|
||||
called(spy: SinonSpy): void;
|
||||
calledOnce(spy: SinonSpy): void;
|
||||
calledTwice(spy: SinonSpy): void;
|
||||
calledThrice(spy: SinonSpy): void;
|
||||
callCount(spy: SinonSpy, count: number): void;
|
||||
callOrder(...spies: SinonSpy[]): void;
|
||||
calledOn(spy: SinonSpy, obj: any): void;
|
||||
alwaysCalledOn(spy: SinonSpy, obj: any): void;
|
||||
calledWith(spy: SinonSpy, ...args: any[]): void;
|
||||
alwaysCalledWith(spy: SinonSpy, ...args: any[]): void;
|
||||
neverCalledWith(spy: SinonSpy, ...args: any[]): void;
|
||||
calledWithExactly(spy: SinonSpy, ...args: any[]): void;
|
||||
alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void;
|
||||
calledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void;
|
||||
alwaysCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void;
|
||||
neverCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void;
|
||||
threw(spy: SinonSpy): void;
|
||||
threw(spy: SinonSpy, exception: string): void;
|
||||
threw(spy: SinonSpy, exception: any): void;
|
||||
alwaysThrew(spy: SinonSpy): void;
|
||||
alwaysThrew(spy: SinonSpy, exception: string): void;
|
||||
alwaysThrew(spy: SinonSpy, exception: any): void;
|
||||
expose(obj: any, options?: SinonExposeOptions): void;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
assert: SinonAssert;
|
||||
}
|
||||
|
||||
interface SinonMatcher {
|
||||
and(expr: SinonMatcher): SinonMatcher;
|
||||
or(expr: SinonMatcher): SinonMatcher;
|
||||
}
|
||||
|
||||
interface SinonMatch {
|
||||
(value: number): SinonMatcher;
|
||||
(value: string): SinonMatcher;
|
||||
(expr: RegExp): SinonMatcher;
|
||||
(obj: any): SinonMatcher;
|
||||
(callback: (value: any) => boolean): SinonMatcher;
|
||||
any: SinonMatcher;
|
||||
defined: SinonMatcher;
|
||||
truthy: SinonMatcher;
|
||||
falsy: SinonMatcher;
|
||||
bool: SinonMatcher;
|
||||
number: SinonMatcher;
|
||||
string: SinonMatcher;
|
||||
object: SinonMatcher;
|
||||
func: SinonMatcher;
|
||||
array: SinonMatcher;
|
||||
regexp: SinonMatcher;
|
||||
date: SinonMatcher;
|
||||
same(obj: any): SinonMatcher;
|
||||
typeOf(type: string): SinonMatcher;
|
||||
instanceOf(type: any): SinonMatcher;
|
||||
has(property: string, expect?: any): SinonMatcher;
|
||||
hasOwn(property: string, expect?: any): SinonMatcher;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
match: SinonMatch;
|
||||
}
|
||||
|
||||
interface SinonSandboxConfig {
|
||||
injectInto?: any;
|
||||
properties?: string[];
|
||||
useFakeTimers?: any;
|
||||
useFakeServer?: any;
|
||||
}
|
||||
|
||||
interface SinonSandbox {
|
||||
clock: SinonFakeTimers;
|
||||
requests: SinonFakeXMLHttpRequest;
|
||||
server: SinonFakeServer;
|
||||
spy: SinonSpyStatic;
|
||||
stub: SinonStubStatic;
|
||||
mock: SinonMockStatic;
|
||||
useFakeTimers: SinonFakeTimersStatic;
|
||||
useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic;
|
||||
useFakeServer(): SinonFakeServer;
|
||||
restore(): void;
|
||||
}
|
||||
|
||||
interface SinonSandboxStatic {
|
||||
create(): SinonSandbox;
|
||||
create(config: SinonSandboxConfig): SinonSandbox;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
sandbox: SinonSandboxStatic;
|
||||
}
|
||||
|
||||
interface SinonTestConfig {
|
||||
injectIntoThis?: boolean;
|
||||
injectInto?: any;
|
||||
properties?: string[];
|
||||
useFakeTimers?: boolean;
|
||||
useFakeServer?: boolean;
|
||||
}
|
||||
|
||||
interface SinonTestWrapper extends SinonSandbox {
|
||||
(...args: any[]): any;
|
||||
}
|
||||
|
||||
interface SinonStatic {
|
||||
config: SinonTestConfig;
|
||||
test(fn: (...args: any[]) => any): SinonTestWrapper;
|
||||
testCase(tests: any): any;
|
||||
}
|
||||
|
||||
// Utility overridables
|
||||
interface SinonStatic {
|
||||
createStubInstance: (constructor: any) => SinonStub;
|
||||
format: (obj: any) => string;
|
||||
log: (message: string) => void;
|
||||
restore(object: any): void;
|
||||
}
|
||||
|
||||
declare var sinon: SinonStatic;
|
||||
declare var sinon: Sinon.SinonStatic;
|
||||
|
||||
declare module "sinon" {
|
||||
export = sinon;
|
||||
|
||||
Reference in New Issue
Block a user