UNPKG

4.22 kBTypeScriptView Raw
1// Type definitions for sinon-chai 3.2.0
2// Project: https://github.com/domenic/sinon-chai
3// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid>
4// Jed Mao <https://github.com/jedmao>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 3.0
7
8/// <reference types="chai" />
9/// <reference types="sinon" />
10
11import * as Sinon from 'sinon';
12
13declare global {
14
15 export namespace Chai {
16
17 interface LanguageChains {
18 always: Assertion;
19 }
20
21 interface Assertion {
22 /**
23 * true if the spy was called at least once.
24 */
25 called: Assertion;
26 /**
27 * @param count The number of recorded calls.
28 */
29 callCount(count: number): Assertion;
30 /**
31 * true if the spy was called exactly once.
32 */
33 calledOnce: Assertion;
34 /**
35 * true if the spy was called exactly twice.
36 */
37 calledTwice: Assertion;
38 /**
39 * true if the spy was called exactly thrice.
40 */
41 calledThrice: Assertion;
42 /**
43 * Returns true if the spy was called before anotherSpy.
44 */
45 calledBefore(anotherSpy: Sinon.SinonSpy|Sinon.SinonSpyCall|Sinon.SinonStub): Assertion;
46 /**
47 * Returns true if the spy was called after anotherSpy.
48 */
49 calledAfter(anotherSpy: Sinon.SinonSpy|Sinon.SinonSpyCall|Sinon.SinonStub): Assertion;
50 /**
51 * Returns true if spy was called before anotherSpy, and no spy calls occurred
52 * between spy and anotherSpy.
53 */
54 calledImmediatelyBefore(anotherSpy: Sinon.SinonSpy|Sinon.SinonStub): Assertion;
55 /**
56 * Returns true if spy was called after anotherSpy, and no spy calls occurred
57 * between anotherSpy and spy.
58 */
59 calledImmediatelyAfter(anotherSpy: Sinon.SinonSpy|Sinon.SinonStub): Assertion;
60 /**
61 * Returns true if spy/stub was called with the new operator. Beware that
62 * this is inferred based on the value of the this object and the spy
63 * function's prototype, so it may give false positives if you actively
64 * return the right kind of object.
65 */
66 calledWithNew: Assertion;
67 /**
68 * Returns true if context was this for this call.
69 */
70 calledOn(context: any): Assertion;
71 /**
72 * Returns true if call received provided arguments (and possibly others).
73 */
74 calledWith(...args: any[]): Assertion;
75 /**
76 * Returns true if spy was called at exactly once with the provided arguments.
77 */
78 calledOnceWith(...args: any[]): Assertion;
79 /**
80 * Returns true if call received provided arguments and no others.
81 */
82 calledWithExactly(...args: any[]): Assertion;
83 /**
84 * Returns true if spy was called exactly once with the provided arguments and no others.
85 */
86 calledOnceWithExactly(...args: any[]): Assertion;
87 /**
88 * Returns true if call received matching arguments (and possibly others).
89 * This behaves the same as spyCall.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
90 */
91 calledWithMatch(...args: any[]): Assertion;
92 /**
93 * Returns true if spy returned the provided value at least once. Uses
94 * deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj))
95 * for strict comparison (see matchers).
96 */
97 returned(obj: any): Assertion;
98 /**
99 * Returns true if spy threw the provided exception object at least once.
100 */
101 thrown(obj?: Error | typeof Error | string): Assertion;
102 }
103 }
104}
105
106declare const sinonChai: Chai.ChaiPlugin;
107declare namespace sinonChai { }
108export = sinonChai;