Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

add root-level hook docs

TJ Holowaychuk1c1b1297f2a7
diff --git a/index.html b/index.html
index 97ac39ef..de7815dc 100644
--- a/index.html
+++ b/index.html
@@ -170,6 +170,13 @@ $ mocha
})
</code></pre>
+<p> You may also pick any file and add &ldquo;root&rdquo; level hooks, for example add <code>beforeEach()</code> outside of <code>describe()</code>s then the callback will run before any test-case regardless of the file its in. This is because Mocha has a root <code>Suite</code> with no name.</p>
+
+<pre><code>beforeEach(function(){
+ console.log('before every test')
+})
+</code></pre>
+
<h2 id="pending-tests">Pending tests</h2>
diff --git a/index.md b/index.md
index 2e630c5c..e1ab7d9c 100644
--- a/index.md
+++ b/index.md
@@ -137,6 +137,12 @@ Testing asynchronous code with Mocha could not be simpler! Simply invoke the cal
})
})
+ You may also pick any file and add "root" level hooks, for example add `beforeEach()` outside of `describe()`s then the callback will run before any test-case regardless of the file its in. This is because Mocha has a root `Suite` with no name.
+
+ beforeEach(function(){
+ console.log('before every test')
+ })
+
<h2 id="pending-tests">Pending tests</h2>
Pending test-cases are simply those without a callback: