| 1 |
--- |
| 2 |
description: The Doc test reporter for Mocha. |
| 3 |
title: Doc |
| 4 |
--- |
| 5 |
|
| 6 |
Alias: `Doc`, `doc` |
| 7 |
|
| 8 |
The Doc reporter outputs a hierarchical HTML body representation of your tests. |
| 9 |
Wrap it with a header, footer, and some styling, then you have some fantastic documentation! |
| 10 |
|
| 11 |
 |
| 12 |
|
| 13 |
For example, suppose you have the following JavaScript: |
| 14 |
|
| 15 |
```js |
| 16 |
describe("Array", function () { |
| 17 |
describe("#indexOf()", function () { |
| 18 |
it("should return -1 when the value is not present", function () { |
| 19 |
[1, 2, 3].indexOf(5).should.equal(-1); |
| 20 |
[1, 2, 3].indexOf(0).should.equal(-1); |
| 21 |
}); |
| 22 |
}); |
| 23 |
}); |
| 24 |
``` |
| 25 |
|
| 26 |
The command `mocha --reporter doc array` would yield: |
| 27 |
|
| 28 |
```html |
| 29 |
<section class="suite"> |
| 30 |
<h1>Array</h1> |
| 31 |
<dl> |
| 32 |
<section class="suite"> |
| 33 |
<h1>#indexOf()</h1> |
| 34 |
<dl> |
| 35 |
<dt>should return -1 when the value is not present</dt> |
| 36 |
<dd> |
| 37 |
<pre><code>[1,2,3].indexOf(5).should.equal(-1); |
| 38 |
[1,2,3].indexOf(0).should.equal(-1);</code></pre> |
| 39 |
</dd> |
| 40 |
</dl> |
| 41 |
</section> |
| 42 |
</dl> |
| 43 |
</section> |
| 44 |
``` |
| 45 |
|
| 46 |
The SuperAgent request library [test documentation](https://ladjs.github.io/superagent/docs/test.html) was generated with Mocha's doc reporter using this Bash command: |
| 47 |
|
| 48 |
```bash |
| 49 |
$ mocha --reporter=doc | cat docs/head.html - docs/tail.html > docs/test.html |
| 50 |
``` |
| 51 |
|
| 52 |
View SuperAgent's [Makefile](https://github.com/visionmedia/superagent/blob/master/Makefile) for reference. |