Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Documented the context feature in BDD interface

oveddanc3caa248b392
diff --git a/index.html b/index.html
index c56810dd..594e84f8 100644
--- a/index.html
+++ b/index.html
@@ -452,7 +452,9 @@ describe('app', function(){
<h3 id="bdd-interface">BDD</h3>
-<p>The "<strong>BDD</strong>" interface provides <code>describe()</code>, <code>it()</code>, <code>before()</code>, <code>after()</code>, <code>beforeEach()</code>, and <code>afterEach()</code>:</p>
+<p>The "<strong>BDD</strong>" interface provides <code>describe()</code>, <code>context()</code>, <code>it()</code>, <code>before()</code>, <code>after()</code>, <code>beforeEach()</code>, and <code>afterEach()</code>:</p>
+
+<p><code>context()</code> is just an alias for <code>describe()</code>, and behaves the same way; it just provides a way to keep tests easier to read and organized.</p>
<pre><code>describe('Array', function(){
before(function(){
@@ -460,8 +462,20 @@ describe('app', function(){
});
describe('#indexOf()', function(){
- it('should return -1 when not present', function(){
- [1,2,3].indexOf(4).should.equal(-1);
+ context('when not present', function(){
+ it('should not throw an error', function(){
+ (function(){
+ [1,2,3].indexOf(4);
+ }).should.not.throw();
+ });
+ it('should return -1', function(){
+ [1,2,3].indexOf(4).should.equal(-1);
+ });
+ });
+ context('when present', function(){
+ it('should return the index where the element first appears in the array', function(){
+ [1,2,3].indexOf(3).should.equal(2);
+ });
});
});
});
@@ -754,7 +768,7 @@ testCase('Array', function(){
<p>Mocha options can be set via <code>mocha.setup()</code>. Examples:</p>
-<pre><code>// Use "tdd" interface. This is a shortcut to setting the interface;
+<pre><code>// Use "tdd" interface. This is a shortcut to setting the interface;
// any other options must be passed via an object.
mocha.setup('tdd');
@@ -901,4 +915,4 @@ mocha.setup({
<span>© 2011 TJ Holowaychuk. All rights reserved.</span>
</footer>
</body>
-</html>
+</html>
\ No newline at end of file
diff --git a/index.md b/index.md
index 0b3d68db..ba1a4a2a 100644
--- a/index.md
+++ b/index.md
@@ -412,7 +412,9 @@ Testing asynchronous code with Mocha could not be simpler! Simply invoke the cal
<h3 id="bdd-interface">BDD</h3>
- The "__BDD__" interface provides `describe()`, `it()`, `before()`, `after()`, `beforeEach()`, and `afterEach()`:
+ The "__BDD__" interface provides `describe()`, `context()`, `it()`, `before()`, `after()`, `beforeEach()`, and `afterEach()`:
+
+ `context()` is just an alias for `describe()`, and behaves the same way; it just provides a way to keep tests easier to read and organized.
describe('Array', function(){
before(function(){
@@ -420,8 +422,20 @@ Testing asynchronous code with Mocha could not be simpler! Simply invoke the cal
});
describe('#indexOf()', function(){
- it('should return -1 when not present', function(){
- [1,2,3].indexOf(4).should.equal(-1);
+ context('when not present', function(){
+ it('should not throw an error', function(){
+ (function(){
+ [1,2,3].indexOf(4);
+ }).should.not.throw();
+ });
+ it('should return -1', function(){
+ [1,2,3].indexOf(4).should.equal(-1);
+ });
+ });
+ context('when present', function(){
+ it('should return the index where the element first appears in the array', function(){
+ [1,2,3].indexOf(3).should.equal(2);
+ });
});
});
});