Skip to content

Commit

Permalink
Merge pull request #1470 from oveddan/gh-pages
Browse files Browse the repository at this point in the history
Documented the context feature in BDD interface
  • Loading branch information
dasilvacontin committed Mar 11, 2015
2 parents b6187a4 + c3caa24 commit 801f8de
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
22 changes: 18 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,30 @@ <h2 id="interfaces">Interfaces</h2>

<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(){
// ...
});

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);
});
});
});
});
Expand Down Expand Up @@ -771,7 +785,7 @@ <h3 id="browser-setup">Mocha Setup in the Browser</h3>

<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');

Expand Down
20 changes: 17 additions & 3 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,30 @@ 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(){
// ...
});

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);
});
});
});
});
Expand Down

0 comments on commit 801f8de

Please sign in to comment.