Permalink
Browse files

Auto register side effects and Update documentation (#872)

* 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...
1 parent 173f786 commit 5a0aa5984eb73fcefe862fe45aa7cc0fa0247bb5 Inanc committed with lucasfcosta Nov 18, 2016
Showing with 43 additions and 24 deletions.
  1. +40 −21 README.md
  2. +0 −1 assert.js
  3. +0 −1 expect.js
  4. +1 −0 register-assert.js
  5. +1 −0 register-expect.js
  6. +1 −0 register-should.js
  7. +0 −1 should.js
View
@@ -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/).
View
@@ -1 +0,0 @@
-global.assert = module.exports = require('./').assert;
View
@@ -1 +0,0 @@
-global.expect = module.exports = require('./').expect;
View
@@ -0,0 +1 @@
+global.assert = require('./').assert;
View
@@ -0,0 +1 @@
+global.expect = require('./').expect;
View
@@ -0,0 +1 @@
+global.should = require('./').should();
View
@@ -1 +0,0 @@
-global.should = module.exports = require('./').should();

0 comments on commit 5a0aa59

Please sign in to comment.