mirror of
https://github.com/chaijs/chai
synced 2024-11-12 23:07:06 +00:00
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
This commit is contained in:
parent
173f786668
commit
5a0aa5984e
7 changed files with 43 additions and 24 deletions
61
README.md
61
README.md
|
@ -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/).
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
global.assert = module.exports = require('./').assert;
|
|
@ -1 +0,0 @@
|
|||
global.expect = module.exports = require('./').expect;
|
1
register-assert.js
Normal file
1
register-assert.js
Normal file
|
@ -0,0 +1 @@
|
|||
global.assert = require('./').assert;
|
1
register-expect.js
Normal file
1
register-expect.js
Normal file
|
@ -0,0 +1 @@
|
|||
global.expect = require('./').expect;
|
1
register-should.js
Normal file
1
register-should.js
Normal file
|
@ -0,0 +1 @@
|
|||
global.should = require('./').should();
|
|
@ -1 +0,0 @@
|
|||
global.should = module.exports = require('./').should();
|
Loading…
Reference in a new issue