Skip to content

Commit

Permalink
Auto register side effects and Update documentation (#872)
Browse files Browse the repository at this point in the history
* Update chai/{testing-style} to chai/register-{testing-style}

* Update documentation on registering side effects and remove module.exports

* Update README.md usage for minor consistency issues
  • Loading branch information
DeeperX authored and lucasfcosta committed Nov 18, 2016
1 parent 173f786 commit 5a0aa59
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
61 changes: 40 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,54 @@ You can also use it within the browser; install via npm and use the `chai.js` fi
Import the library in your code, and then pick one of the styles you'd like to use - either `assert`, `expect` or `should`:

```js
var chai = require('chai');
// Using Assert style
var assert = chai.assert;
// Using Expect style
var expect = chai.expect;
// Using Should style
var should = chai.should();
var chai = require('chai');
var assert = chai.assert; // Using Assert style
var expect = chai.expect; // Using Expect style
var should = chai.should(); // Using Should style
```

## Native Modules Usage
### Pre-Native Modules Usage (_registers the chai testing style globally_)

```js
import assert from 'chai/assert'
// Using Assert style
import expect from 'chai/expect'
// Using Expect style
import should from 'chai/should'
// Using Should style
require('chai/register-assert'); // Using Assert style
require('chai/register-expect'); // Using Expect style
require('chai/register-should'); // Using Should style
```

## Usage with Mocha
### Pre-Native Modules Usage (_as local variables_)

```js
const { assert } = require('chai'); // Using Assert style
const { expect } = require('chai'); // Using Expect style
const { should } = require('chai'); // Using Should style
should(); // Modifies `Object.prototype`

const { expect, use } = require('chai'); // Creates local variables `expect` and `use`; useful for plugin use
```

### Native Modules Usage (_registers the chai testing style globally_)

```js
import 'chai/register-assert'; // Using Assert style
import 'chai/register-expect'; // Using Expect style
import 'chai/register-should'; // Using Should style
```

### Native Modules Usage (_local import only_)

```js
import { assert } from 'chai'; // Using Assert style
import { expect } from 'chai'; // Using Expect style
import { should } from 'chai'; // Using Should style
should(); // Modifies `Object.prototype`
```

### Usage with Mocha

```bash
mocha spec.js -r chai/assert # OR:
# Using Assert style
mocha spec.js -r chai/expect # OR:
# Using Expect style
mocha spec.js -r chai/should
# Using Should style
mocha spec.js -r chai/register-assert # Using Assert style
mocha spec.js -r chai/register-expect # Using Expect style
mocha spec.js -r chai/register-should # Using Should style
```

[Read more about these styles in our docs](http://chaijs.com/guide/styles/).
Expand Down
1 change: 0 additions & 1 deletion assert.js

This file was deleted.

1 change: 0 additions & 1 deletion expect.js

This file was deleted.

1 change: 1 addition & 0 deletions register-assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.assert = require('./').assert;
1 change: 1 addition & 0 deletions register-expect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.expect = require('./').expect;
1 change: 1 addition & 0 deletions register-should.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.should = require('./').should();
1 change: 0 additions & 1 deletion should.js

This file was deleted.

0 comments on commit 5a0aa59

Please sign in to comment.