Repository: chaijs/chai (js)

Issue:
"use" doesn't behave as expected as an ES6 named export
The following code throws an error:

```js
import sinonChai from "sinon-chai";
import {expect, use} from "chai";

use(sinonChai);
```

The reason it throws an error is because the necessary `this` binding is lost when calling `use` via the above syntax as opposed to calling it via `chai.use(sinonChai)`.

I'd argue that it's unexpected and undesirable for a singleton module to utilize `this` in such a way.

One possible solution might be to change [use](https://github.com/chaijs/chai/blob/2194a89e0290a3152446995afe877d4248256c91/lib/chai.js#L38-L45) from:

```js
exports.use = function (fn) {
  if (!~used.indexOf(fn)) {
    fn(this, util);
    used.push(fn);
  }

  return this;
};
```

To:

```js
exports.use = function (fn) {
  if (!~used.indexOf(fn)) {
    fn(exports, util);
    used.push(fn);
  }

  return exports;
};
```

Pull request description:
Fix chai.use as ES6 named export
- Fixes #718 
- Allows `use` to be imported in ES6 as follows:
```js
import {use} from "chai";
```

Patch:
diff --git a/lib/chai.js b/lib/chai.js
index 888b485..faa54c9 100644
--- a/lib/chai.js
+++ b/lib/chai.js
@@ -37,11 +37,11 @@ var util = require('./chai/utils');
 
 exports.use = function (fn) {
   if (!~used.indexOf(fn)) {
-    fn(this, util);
+    fn(exports, util);
     used.push(fn);
   }
 
-  return this;
+  return exports;
 };
 
 /*!


Test patch:
diff --git a/test/plugins.js b/test/plugins.js
index c6df554..f56336c 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -21,4 +21,20 @@ describe('plugins', function () {
       chai.use(plugin);
     }).to.not.throw();
   });
+
+  it('.use detached from chai object', function () {
+    function anotherPlugin (chai) {
+      Object.defineProperty(chai.Assertion.prototype, 'moreTesting', {
+        get: function () {
+          return 'more success';
+        }
+      });
+    }
+
+    var use = chai.use;
+    use(anotherPlugin);
+
+    var expect = chai.expect;
+    expect(expect('').moreTesting).to.equal('more success');
+  });
 });