mocha.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Type definitions for mocha 2.0.1
  2. // Project: http://mochajs.org/
  3. // Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>, jt000 <https://github.com/jt000>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. interface Mocha {
  6. // Setup mocha with the given setting options.
  7. setup(options: MochaSetupOptions): Mocha;
  8. //Run tests and invoke `fn()` when complete.
  9. run(callback?: () => void): void;
  10. // Set reporter as function
  11. reporter(reporter: () => void): Mocha;
  12. // Set reporter, defaults to "dot"
  13. reporter(reporter: string): Mocha;
  14. // Enable growl support.
  15. growl(): Mocha
  16. }
  17. interface MochaSetupOptions {
  18. //milliseconds to wait before considering a test slow
  19. slow?: number;
  20. // timeout in milliseconds
  21. timeout?: number;
  22. // ui name "bdd", "tdd", "exports" etc
  23. ui?: string;
  24. //array of accepted globals
  25. globals?: any[];
  26. // reporter instance (function or string), defaults to `mocha.reporters.Dot`
  27. reporter?: any;
  28. // bail on the first test failure
  29. bail?: boolean;
  30. // ignore global leaks
  31. ignoreLeaks?: boolean;
  32. // grep string or regexp to filter tests with
  33. grep?: any;
  34. }
  35. interface MochaDone {
  36. (error?: Error): void;
  37. }
  38. declare var mocha: Mocha;
  39. declare var describe : {
  40. (description: string, spec: () => void): void;
  41. only(description: string, spec: () => void): void;
  42. skip(description: string, spec: () => void): void;
  43. timeout(ms: number): void;
  44. }
  45. // alias for `describe`
  46. declare var context : {
  47. (contextTitle: string, spec: () => void): void;
  48. only(contextTitle: string, spec: () => void): void;
  49. skip(contextTitle: string, spec: () => void): void;
  50. timeout(ms: number): void;
  51. }
  52. declare var it: {
  53. (expectation: string, assertion?: () => void): void;
  54. (expectation: string, assertion?: (done: MochaDone) => void): void;
  55. only(expectation: string, assertion?: () => void): void;
  56. only(expectation: string, assertion?: (done: MochaDone) => void): void;
  57. skip(expectation: string, assertion?: () => void): void;
  58. skip(expectation: string, assertion?: (done: MochaDone) => void): void;
  59. timeout(ms: number): void;
  60. };
  61. declare function before(action: () => void): void;
  62. declare function before(action: (done: MochaDone) => void): void;
  63. declare function setup(action: () => void): void;
  64. declare function setup(action: (done: MochaDone) => void): void;
  65. declare function after(action: () => void): void;
  66. declare function after(action: (done: MochaDone) => void): void;
  67. declare function teardown(action: () => void): void;
  68. declare function teardown(action: (done: MochaDone) => void): void;
  69. declare function beforeEach(action: () => void): void;
  70. declare function beforeEach(action: (done: MochaDone) => void): void;
  71. declare function suiteSetup(action: () => void): void;
  72. declare function suiteSetup(action: (done: MochaDone) => void): void;
  73. declare function afterEach(action: () => void): void;
  74. declare function afterEach(action: (done: MochaDone) => void): void;
  75. declare function suiteTeardown(action: () => void): void;
  76. declare function suiteTeardown(action: (done: MochaDone) => void): void;
  77. declare module "mocha" {
  78. class Mocha {
  79. constructor(options?: {
  80. grep?: RegExp;
  81. ui?: string;
  82. reporter?: string;
  83. timeout?: number;
  84. bail?: boolean;
  85. });
  86. bail(value?: boolean): Mocha;
  87. addFile(file: string): Mocha;
  88. reporter(value: string): Mocha;
  89. ui(value: string): Mocha;
  90. grep(value: string): Mocha;
  91. grep(value: RegExp): Mocha;
  92. invert(): Mocha;
  93. ignoreLeaks(value: boolean): Mocha;
  94. checkLeaks(): Mocha;
  95. growl(): Mocha;
  96. globals(value: string): Mocha;
  97. globals(values: string[]): Mocha;
  98. useColors(value: boolean): Mocha;
  99. useInlineDiffs(value: boolean): Mocha;
  100. timeout(value: number): Mocha;
  101. slow(value: number): Mocha;
  102. enableTimeouts(value: boolean): Mocha;
  103. asyncOnly(value: boolean): Mocha;
  104. noHighlighting(value: boolean): Mocha;
  105. run(onComplete?: (failures: number) => void): void;
  106. }
  107. export = Mocha;
  108. }