expect.js.d.ts 4.9 KB

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