Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"use" doesn't behave as expected as an ES6 named export #718

Closed
meeber opened this issue Jun 5, 2016 · 2 comments
Closed

"use" doesn't behave as expected as an ES6 named export #718

meeber opened this issue Jun 5, 2016 · 2 comments
Labels

Comments

@meeber
Copy link
Contributor

meeber commented Jun 5, 2016

The following code throws an error:

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 from:

exports.use = function (fn) {
  if (!~used.indexOf(fn)) {
    fn(this, util);
    used.push(fn);
  }

  return this;
};

To:

exports.use = function (fn) {
  if (!~used.indexOf(fn)) {
    fn(exports, util);
    used.push(fn);
  }

  return exports;
};
@lucasfcosta
Copy link
Member

Looks good to me.
Since this and exports refer to the same object (which is the chai module which is being exported by this file) I can't see any other side effects for this.
Nice catch 👍

@lucasfcosta lucasfcosta added the bug label Jun 9, 2016
@meeber
Copy link
Contributor Author

meeber commented Jun 9, 2016

@lucasfcosta Thanks for checking this out. I'll prolly submit a PR after work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants