expect.js.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Type definitions for expect.js 0.3.1
  2. // Project: https://github.com/Automattic/expect.js
  3. // Definitions by: Teppei Sato <https://github.com/teppeis>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. declare function expect(target?: any): Expect.Root;
  6. declare module Expect {
  7. interface Assertion {
  8. /**
  9. * Check if the value is truthy
  10. */
  11. ok(): void;
  12. /**
  13. * Creates an anonymous function which calls fn with arguments.
  14. */
  15. withArgs(...args: any[]): Root;
  16. /**
  17. * Assert that the function throws.
  18. *
  19. * @param fn callback to match error string against
  20. */
  21. throwError(fn?: (exception: any) => void): void;
  22. /**
  23. * Assert that the function throws.
  24. *
  25. * @param fn callback to match error string against
  26. */
  27. throwException(fn?: (exception: any) => void): void;
  28. /**
  29. * Assert that the function throws.
  30. *
  31. * @param regexp regexp to match error string against
  32. */
  33. throwError(regexp: RegExp): void;
  34. /**
  35. * Assert that the function throws.
  36. *
  37. * @param fn callback to match error string against
  38. */
  39. throwException(regexp: RegExp): void;
  40. /**
  41. * Checks if the array is empty.
  42. */
  43. empty(): Assertion;
  44. /**
  45. * Checks if the obj exactly equals another.
  46. */
  47. equal(obj: any): Assertion;
  48. /**
  49. * Checks if the obj sortof equals another.
  50. */
  51. eql(obj: any): Assertion;
  52. /**
  53. * Assert within start to finish (inclusive).
  54. *
  55. * @param start
  56. * @param finish
  57. */
  58. within(start: number, finish: number): Assertion;
  59. /**
  60. * Assert typeof.
  61. */
  62. a(type: string): Assertion;
  63. /**
  64. * Assert instanceof.
  65. */
  66. a(type: Function): Assertion;
  67. /**
  68. * Assert typeof / instanceof.
  69. */
  70. an: An;
  71. /**
  72. * Assert numeric value above n.
  73. */
  74. greaterThan(n: number): Assertion;
  75. /**
  76. * Assert numeric value above n.
  77. */
  78. above(n: number): Assertion;
  79. /**
  80. * Assert numeric value below n.
  81. */
  82. lessThan(n: number): Assertion;
  83. /**
  84. * Assert numeric value below n.
  85. */
  86. below(n: number): Assertion;
  87. /**
  88. * Assert string value matches regexp.
  89. *
  90. * @param regexp
  91. */
  92. match(regexp: RegExp): Assertion;
  93. /**
  94. * Assert property "length" exists and has value of n.
  95. *
  96. * @param n
  97. */
  98. length(n: number): Assertion;
  99. /**
  100. * Assert property name exists, with optional val.
  101. *
  102. * @param name
  103. * @param val
  104. */
  105. property(name: string, val?: any): Assertion;
  106. /**
  107. * Assert that string contains str.
  108. */
  109. contain(str: string): Assertion;
  110. string(str: string): Assertion;
  111. /**
  112. * Assert that the array contains obj.
  113. */
  114. contain(obj: any): Assertion;
  115. string(obj: any): Assertion;
  116. /**
  117. * Assert exact keys or inclusion of keys by using the `.own` modifier.
  118. */
  119. key(keys: string[]): Assertion;
  120. /**
  121. * Assert exact keys or inclusion of keys by using the `.own` modifier.
  122. */
  123. key(...keys: string[]): Assertion;
  124. /**
  125. * Assert exact keys or inclusion of keys by using the `.own` modifier.
  126. */
  127. keys(keys: string[]): Assertion;
  128. /**
  129. * Assert exact keys or inclusion of keys by using the `.own` modifier.
  130. */
  131. keys(...keys: string[]): Assertion;
  132. /**
  133. * Assert a failure.
  134. */
  135. fail(message?: string): Assertion;
  136. }
  137. interface Root extends Assertion {
  138. not: Not;
  139. to: To;
  140. only: Only;
  141. have: Have;
  142. be: Be;
  143. }
  144. interface Be extends Assertion {
  145. /**
  146. * Checks if the obj exactly equals another.
  147. */
  148. (obj: any): Assertion;
  149. an: An;
  150. }
  151. interface An extends Assertion {
  152. /**
  153. * Assert typeof.
  154. */
  155. (type: string): Assertion;
  156. /**
  157. * Assert instanceof.
  158. */
  159. (type: Function): Assertion;
  160. }
  161. interface Not extends Expect.NotBase {
  162. to: Expect.ToBase;
  163. }
  164. interface NotBase extends Assertion {
  165. be: Be;
  166. have: Have;
  167. include: Assertion;
  168. only: Only;
  169. }
  170. interface To extends Expect.ToBase {
  171. not: Expect.NotBase;
  172. }
  173. interface ToBase extends Assertion {
  174. be: Be;
  175. have: Have;
  176. include: Assertion;
  177. only: Only;
  178. }
  179. interface Only extends Assertion {
  180. have: Have;
  181. }
  182. interface Have extends Assertion {
  183. own: Assertion;
  184. }
  185. }
  186. declare module "expect.js" {
  187. export = expect;
  188. }