Skip to content
This repository has been archived by the owner on Jan 4, 2018. It is now read-only.

Getting started run test #58

Merged
merged 4 commits into from
Nov 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ $ npm install --global mocha
```

or as a development dependency for your project:

```sh
$ npm install --save-dev mocha
```
Expand Down Expand Up @@ -117,6 +117,8 @@ describe('Array', function() {
Back in the terminal:

```sh
$ ./node_modules/mocha/bin/mocha

Array
#indexOf()
✓ should return -1 when the value is not present
Expand All @@ -125,6 +127,20 @@ Back in the terminal:
1 passing (9ms)
```

Set up a test script in package.json:

```json
"scripts": {
"test": "mocha"
}
```

Then run tests with:

```sh
$ npm test
```

## Assertions

Mocha allows you to use any assertion library you wish. In the above example, we're using Node.js' built-in [assert](https://nodejs.org/api/assert.html) module--but generally, if it throws an `Error`, it will work! This means you can use libraries such as:
Expand Down Expand Up @@ -395,7 +411,7 @@ describe('Array', function() {
it.only('should return the index when present', function() {
// this test will also be run
});

it('should return -1 if called with a non-Array context', function() {
// this test will not be run
});
Expand All @@ -416,13 +432,13 @@ describe('Array', function() {
// this test will also be run
});
});

describe.only('#concat()', function () {
it('should return a new Array', function () {
// this test will also be run
});
});

describe('#slice()', function () {
it('should return a new Array', function () {
// this test will not be run
Expand Down Expand Up @@ -539,11 +555,11 @@ This feature does re-run `beforeEach/afterEach` hooks but not `before/after` hoo
describe('retries', function() {
// Retry all tests in this suite up to 4 times
this.retries(4);

beforeEach(function () {
browser.get('http://www.yahoo.com');
});

it('should succeed on the 3rd try', function () {
// Specify this test to only retry up to 2 times
this.retries(2);
Expand Down Expand Up @@ -660,7 +676,7 @@ describe('a suite of tests', function() {

Again, use `this.timeout(0)` to disable the timeout for a hook.

> In v3.0.0 or newer, a parameter passed to `this.timeout()` greater than the [maximum delay value](https://developer.mozilla.org/docs/Web/API/WindowTimers/setTimeout#Maximum_delay_value) will cause the timeout to be disabled.
> In v3.0.0 or newer, a parameter passed to `this.timeout()` greater than the [maximum delay value](https://developer.mozilla.org/docs/Web/API/WindowTimers/setTimeout#Maximum_delay_value) will cause the timeout to be disabled.

## Diffs

Expand Down Expand Up @@ -742,7 +758,7 @@ name. For example `--compilers coffee:coffee-script` with CoffeeScript 1.6- or

#### About Babel

If your ES6 modules have extension `.js`, you can `npm install --save-dev babel-register` and use `mocha --require babel-register`; `--compilers` is only necessary if you need to specify a file extension.
If your ES6 modules have extension `.js`, you can `npm install --save-dev babel-register` and use `mocha --require babel-register`; `--compilers` is only necessary if you need to specify a file extension.

### `-b, --bail`

Expand Down