index.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // Generated by typings
  2. // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/sinon/sinon.d.ts
  3. declare namespace Sinon {
  4. interface SinonSpyCallApi {
  5. // Properties
  6. thisValue: any;
  7. args: any[];
  8. exception: any;
  9. returnValue: any;
  10. // Methods
  11. calledOn(obj: any): boolean;
  12. calledWith(...args: any[]): boolean;
  13. calledWithExactly(...args: any[]): boolean;
  14. calledWithMatch(...args: any[]): boolean;
  15. notCalledWith(...args: any[]): boolean;
  16. notCalledWithMatch(...args: any[]): boolean;
  17. returned(value: any): boolean;
  18. threw(): boolean;
  19. threw(type: string): boolean;
  20. threw(obj: any): boolean;
  21. callArg(pos: number): void;
  22. callArgOn(pos: number, obj: any, ...args: any[]): void;
  23. callArgWith(pos: number, ...args: any[]): void;
  24. callArgOnWith(pos: number, obj: any, ...args: any[]): void;
  25. yield(...args: any[]): void;
  26. yieldOn(obj: any, ...args: any[]): void;
  27. yieldTo(property: string, ...args: any[]): void;
  28. yieldToOn(property: string, obj: any, ...args: any[]): void;
  29. }
  30. interface SinonSpyCall extends SinonSpyCallApi {
  31. calledBefore(call: SinonSpyCall): boolean;
  32. calledAfter(call: SinonSpyCall): boolean;
  33. calledWithNew(call: SinonSpyCall): boolean;
  34. }
  35. interface SinonSpy extends SinonSpyCallApi {
  36. // Properties
  37. callCount: number;
  38. called: boolean;
  39. notCalled: boolean;
  40. calledOnce: boolean;
  41. calledTwice: boolean;
  42. calledThrice: boolean;
  43. firstCall: SinonSpyCall;
  44. secondCall: SinonSpyCall;
  45. thirdCall: SinonSpyCall;
  46. lastCall: SinonSpyCall;
  47. thisValues: any[];
  48. args: any[][];
  49. exceptions: any[];
  50. returnValues: any[];
  51. // Methods
  52. (...args: any[]): any;
  53. calledBefore(anotherSpy: SinonSpy): boolean;
  54. calledAfter(anotherSpy: SinonSpy): boolean;
  55. calledWithNew(): boolean;
  56. withArgs(...args: any[]): SinonSpy;
  57. alwaysCalledOn(obj: any): boolean;
  58. alwaysCalledWith(...args: any[]): boolean;
  59. alwaysCalledWithExactly(...args: any[]): boolean;
  60. alwaysCalledWithMatch(...args: any[]): boolean;
  61. neverCalledWith(...args: any[]): boolean;
  62. neverCalledWithMatch(...args: any[]): boolean;
  63. alwaysThrew(): boolean;
  64. alwaysThrew(type: string): boolean;
  65. alwaysThrew(obj: any): boolean;
  66. alwaysReturned(): boolean;
  67. invokeCallback(...args: any[]): void;
  68. getCall(n: number): SinonSpyCall;
  69. reset(): void;
  70. printf(format: string, ...args: any[]): string;
  71. restore(): void;
  72. }
  73. interface SinonSpyStatic {
  74. (): SinonSpy;
  75. (func: any): SinonSpy;
  76. (obj: any, method: string): SinonSpy;
  77. }
  78. interface SinonStatic {
  79. spy: SinonSpyStatic;
  80. }
  81. interface SinonStub extends SinonSpy {
  82. resetBehavior(): void;
  83. returns(obj: any): SinonStub;
  84. returnsArg(index: number): SinonStub;
  85. returnsThis(): SinonStub;
  86. throws(type?: string): SinonStub;
  87. throws(obj: any): SinonStub;
  88. callsArg(index: number): SinonStub;
  89. callsArgOn(index: number, context: any): SinonStub;
  90. callsArgWith(index: number, ...args: any[]): SinonStub;
  91. callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub;
  92. callsArgAsync(index: number): SinonStub;
  93. callsArgOnAsync(index: number, context: any): SinonStub;
  94. callsArgWithAsync(index: number, ...args: any[]): SinonStub;
  95. callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub;
  96. onCall(n: number): SinonStub;
  97. onFirstCall(): SinonStub;
  98. onSecondCall(): SinonStub;
  99. onThirdCall(): SinonStub;
  100. yields(...args: any[]): SinonStub;
  101. yieldsOn(context: any, ...args: any[]): SinonStub;
  102. yieldsTo(property: string, ...args: any[]): SinonStub;
  103. yieldsToOn(property: string, context: any, ...args: any[]): SinonStub;
  104. yieldsAsync(...args: any[]): SinonStub;
  105. yieldsOnAsync(context: any, ...args: any[]): SinonStub;
  106. yieldsToAsync(property: string, ...args: any[]): SinonStub;
  107. yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub;
  108. withArgs(...args: any[]): SinonStub;
  109. }
  110. interface SinonStubStatic {
  111. (): SinonStub;
  112. (obj: any): SinonStub;
  113. (obj: any, method: string): SinonStub;
  114. (obj: any, method: string, func: any): SinonStub;
  115. }
  116. interface SinonStatic {
  117. stub: SinonStubStatic;
  118. }
  119. interface SinonExpectation extends SinonStub {
  120. atLeast(n: number): SinonExpectation;
  121. atMost(n: number): SinonExpectation;
  122. never(): SinonExpectation;
  123. once(): SinonExpectation;
  124. twice(): SinonExpectation;
  125. thrice(): SinonExpectation;
  126. exactly(n: number): SinonExpectation;
  127. withArgs(...args: any[]): SinonExpectation;
  128. withExactArgs(...args: any[]): SinonExpectation;
  129. on(obj: any): SinonExpectation;
  130. verify(): SinonExpectation;
  131. restore(): void;
  132. }
  133. interface SinonExpectationStatic {
  134. create(methodName?: string): SinonExpectation;
  135. }
  136. interface SinonMock {
  137. expects(method: string): SinonExpectation;
  138. restore(): void;
  139. verify(): void;
  140. }
  141. interface SinonMockStatic {
  142. (): SinonExpectation;
  143. (obj: any): SinonMock;
  144. }
  145. interface SinonStatic {
  146. expectation: SinonExpectationStatic;
  147. mock: SinonMockStatic;
  148. }
  149. interface SinonFakeTimers {
  150. now: number;
  151. create(now: number): SinonFakeTimers;
  152. setTimeout(callback: (...args: any[]) => void, timeout: number, ...args: any[]): number;
  153. clearTimeout(id: number): void;
  154. setInterval(callback: (...args: any[]) => void, timeout: number, ...args: any[]): number;
  155. clearInterval(id: number): void;
  156. tick(ms: number): number;
  157. reset(): void;
  158. Date(): Date;
  159. Date(year: number): Date;
  160. Date(year: number, month: number): Date;
  161. Date(year: number, month: number, day: number): Date;
  162. Date(year: number, month: number, day: number, hour: number): Date;
  163. Date(year: number, month: number, day: number, hour: number, minute: number): Date;
  164. Date(year: number, month: number, day: number, hour: number, minute: number, second: number): Date;
  165. Date(year: number, month: number, day: number, hour: number, minute: number, second: number, ms: number): Date;
  166. restore(): void;
  167. /**
  168. * Simulate the user changing the system clock while your program is running. It changes the 'now' timestamp
  169. * without affecting timers, intervals or immediates.
  170. * @param now The new 'now' in unix milliseconds
  171. */
  172. setSystemTime(now: number): void;
  173. /**
  174. * Simulate the user changing the system clock while your program is running. It changes the 'now' timestamp
  175. * without affecting timers, intervals or immediates.
  176. * @param now The new 'now' as a JavaScript Date
  177. */
  178. setSystemTime(date: Date): void;
  179. }
  180. interface SinonFakeTimersStatic {
  181. (): SinonFakeTimers;
  182. (...timers: string[]): SinonFakeTimers;
  183. (now: number, ...timers: string[]): SinonFakeTimers;
  184. }
  185. interface SinonStatic {
  186. useFakeTimers: SinonFakeTimersStatic;
  187. clock: SinonFakeTimers;
  188. }
  189. interface SinonFakeUploadProgress {
  190. eventListeners: {
  191. progress: any[];
  192. load: any[];
  193. abort: any[];
  194. error: any[];
  195. };
  196. addEventListener(event: string, listener: (e: Event) => any): void;
  197. removeEventListener(event: string, listener: (e: Event) => any): void;
  198. dispatchEvent(event: Event): void;
  199. }
  200. interface SinonFakeXMLHttpRequest {
  201. // Properties
  202. onCreate: (xhr: SinonFakeXMLHttpRequest) => void;
  203. url: string;
  204. method: string;
  205. requestHeaders: any;
  206. requestBody: string;
  207. status: number;
  208. statusText: string;
  209. async: boolean;
  210. username: string;
  211. password: string;
  212. withCredentials: boolean;
  213. upload: SinonFakeUploadProgress;
  214. responseXML: Document;
  215. getResponseHeader(header: string): string;
  216. getAllResponseHeaders(): any;
  217. // Methods
  218. restore(): void;
  219. useFilters: boolean;
  220. addFilter(filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean): void;
  221. setResponseHeaders(headers: any): void;
  222. setResponseBody(body: string): void;
  223. respond(status: number, headers: any, body: string): void;
  224. autoRespond(ms: number): void;
  225. }
  226. interface SinonFakeXMLHttpRequestStatic {
  227. (): SinonFakeXMLHttpRequest;
  228. }
  229. interface SinonStatic {
  230. useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic;
  231. FakeXMLHttpRequest: SinonFakeXMLHttpRequest;
  232. }
  233. interface SinonFakeServer {
  234. // Properties
  235. autoRespond: boolean;
  236. autoRespondAfter: number;
  237. fakeHTTPMethods: boolean;
  238. getHTTPMethod: (request: SinonFakeXMLHttpRequest) => string;
  239. requests: SinonFakeXMLHttpRequest[];
  240. respondImmediately: boolean;
  241. // Methods
  242. respondWith(body: string): void;
  243. respondWith(response: any[]): void;
  244. respondWith(fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
  245. respondWith(url: string, body: string): void;
  246. respondWith(url: string, response: any[]): void;
  247. respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
  248. respondWith(method: string, url: string, body: string): void;
  249. respondWith(method: string, url: string, response: any[]): void;
  250. respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
  251. respondWith(url: RegExp, body: string): void;
  252. respondWith(url: RegExp, response: any[]): void;
  253. respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
  254. respondWith(method: string, url: RegExp, body: string): void;
  255. respondWith(method: string, url: RegExp, response: any[]): void;
  256. respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
  257. respond(): void;
  258. restore(): void;
  259. }
  260. interface SinonFakeServerStatic {
  261. create(): SinonFakeServer;
  262. }
  263. interface SinonStatic {
  264. fakeServer: SinonFakeServerStatic;
  265. fakeServerWithClock: SinonFakeServerStatic;
  266. }
  267. interface SinonExposeOptions {
  268. prefix?: string;
  269. includeFail?: boolean;
  270. }
  271. interface SinonAssert {
  272. // Properties
  273. failException: string;
  274. fail: (message?: string) => void; // Overridable
  275. pass: (assertion: any) => void; // Overridable
  276. // Methods
  277. notCalled(spy: SinonSpy): void;
  278. called(spy: SinonSpy): void;
  279. calledOnce(spy: SinonSpy): void;
  280. calledTwice(spy: SinonSpy): void;
  281. calledThrice(spy: SinonSpy): void;
  282. callCount(spy: SinonSpy, count: number): void;
  283. callOrder(...spies: SinonSpy[]): void;
  284. calledOn(spy: SinonSpy, obj: any): void;
  285. alwaysCalledOn(spy: SinonSpy, obj: any): void;
  286. calledWith(spy: SinonSpy, ...args: any[]): void;
  287. alwaysCalledWith(spy: SinonSpy, ...args: any[]): void;
  288. neverCalledWith(spy: SinonSpy, ...args: any[]): void;
  289. calledWithExactly(spy: SinonSpy, ...args: any[]): void;
  290. alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void;
  291. calledWithMatch(spy: SinonSpy, ...args: any[]): void;
  292. alwaysCalledWithMatch(spy: SinonSpy, ...args: any[]): void;
  293. neverCalledWithMatch(spy: SinonSpy, ...args: any[]): void;
  294. threw(spy: SinonSpy): void;
  295. threw(spy: SinonSpy, exception: string): void;
  296. threw(spy: SinonSpy, exception: any): void;
  297. alwaysThrew(spy: SinonSpy): void;
  298. alwaysThrew(spy: SinonSpy, exception: string): void;
  299. alwaysThrew(spy: SinonSpy, exception: any): void;
  300. expose(obj: any, options?: SinonExposeOptions): void;
  301. }
  302. interface SinonStatic {
  303. assert: SinonAssert;
  304. }
  305. interface SinonMatcher {
  306. and(expr: SinonMatcher): SinonMatcher;
  307. or(expr: SinonMatcher): SinonMatcher;
  308. }
  309. interface SinonMatch {
  310. (value: number): SinonMatcher;
  311. (value: string): SinonMatcher;
  312. (expr: RegExp): SinonMatcher;
  313. (obj: any): SinonMatcher;
  314. (callback: (value: any) => boolean): SinonMatcher;
  315. any: SinonMatcher;
  316. defined: SinonMatcher;
  317. truthy: SinonMatcher;
  318. falsy: SinonMatcher;
  319. bool: SinonMatcher;
  320. number: SinonMatcher;
  321. string: SinonMatcher;
  322. object: SinonMatcher;
  323. func: SinonMatcher;
  324. array: SinonMatcher;
  325. regexp: SinonMatcher;
  326. date: SinonMatcher;
  327. same(obj: any): SinonMatcher;
  328. typeOf(type: string): SinonMatcher;
  329. instanceOf(type: any): SinonMatcher;
  330. has(property: string, expect?: any): SinonMatcher;
  331. hasOwn(property: string, expect?: any): SinonMatcher;
  332. }
  333. interface SinonStatic {
  334. match: SinonMatch;
  335. }
  336. interface SinonSandboxConfig {
  337. injectInto?: any;
  338. properties?: string[];
  339. useFakeTimers?: any;
  340. useFakeServer?: any;
  341. }
  342. interface SinonSandbox {
  343. clock: SinonFakeTimers;
  344. requests: SinonFakeXMLHttpRequest;
  345. server: SinonFakeServer;
  346. spy: SinonSpyStatic;
  347. stub: SinonStubStatic;
  348. mock: SinonMockStatic;
  349. useFakeTimers: SinonFakeTimersStatic;
  350. useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic;
  351. useFakeServer(): SinonFakeServer;
  352. restore(): void;
  353. }
  354. interface SinonSandboxStatic {
  355. create(): SinonSandbox;
  356. create(config: SinonSandboxConfig): SinonSandbox;
  357. }
  358. interface SinonStatic {
  359. sandbox: SinonSandboxStatic;
  360. }
  361. interface SinonTestConfig {
  362. injectIntoThis?: boolean;
  363. injectInto?: any;
  364. properties?: string[];
  365. useFakeTimers?: boolean;
  366. useFakeServer?: boolean;
  367. }
  368. interface SinonTestWrapper extends SinonSandbox {
  369. (...args: any[]): any;
  370. }
  371. interface SinonStatic {
  372. config: SinonTestConfig;
  373. test(fn: (...args: any[]) => any): SinonTestWrapper;
  374. testCase(tests: any): any;
  375. }
  376. // Utility overridables
  377. interface SinonStatic {
  378. createStubInstance(constructor: any): SinonStub;
  379. format(obj: any): string;
  380. log(message: string): void;
  381. restore(object: any): void;
  382. }
  383. }
  384. declare var sinon: Sinon.SinonStatic;
  385. declare module "sinon" {
  386. export = sinon;
  387. }