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

🚀 Feature: New interface to support arrow functions #2657

Closed
alexreardon opened this issue Jan 3, 2017 · 8 comments
Closed

🚀 Feature: New interface to support arrow functions #2657

alexreardon opened this issue Jan 3, 2017 · 8 comments
Labels
status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior type: feature enhancement proposal

Comments

@alexreardon
Copy link

Currently functions that use () => cannot take advantage of the mocha context: http://mochajs.org/#arrow-functions.

However, arrow function usage could be improved by passing the context as an argument:

it('should do something cool', (done, context) => {
  context.timeout = 5000;
  ...
});

The complicating factor is the done argument. The presence of which makes the test async. Perhaps if you want to use the context argument then you need to also call done when appropriate.

@Munter
Copy link
Contributor

Munter commented Jan 3, 2017

function () { this.timeout = 5000; } is less typing than (done, context) => { context.timeout = 5000; }

Forcing the function to be async to enable people to access the context seems like a pretty annoying API.

I still have no clue why people want to use arrow functions when it explicitly does the wrong thing in mochas context

@laggingreflex
Copy link

Came here for this, but I've also found https://github.com/skozin/arrow-mocha

@drazisil drazisil added the type: feature enhancement proposal label Mar 30, 2017
@eight04
Copy link

eight04 commented May 23, 2018

Here is a version which can work with mocha's --require option:
https://www.npmjs.com/package/mocha-context

@Bamieh
Copy link
Contributor

Bamieh commented May 23, 2018

@alexreardon thanks for the suggestion, You can always do the following as well:

it('some case', () => {
  expect(1 + 2).to.equal(3);
}).timeout(1000);

@Bamieh Bamieh added the status: waiting for author waiting on response from OP - more information needed label May 23, 2018
@boneskull boneskull added status: accepting prs Mocha can use your help with this one! and removed status: waiting for author waiting on response from OP - more information needed labels May 29, 2018
@boneskull
Copy link
Contributor

Replacing the default bdd interface with this is a non-starter.

It's possible to create an interface which passes the context as the first parameter, but would likely require modifications to Mocha's core to support, due to hardcoded assumptions.

Would accept a PR that would allow the "async check" of an interface to be configurable. Once that's ready, then it should be fairly trivial to provide an alternate interface.

@boneskull boneskull changed the title Idea: improved arrow function usage enhancement: new interface to support arrow functions May 29, 2018
@eight04
Copy link

eight04 commented May 30, 2018

allow the "async check" of an interface to be configurable.

What does it mean?

I think this feature could be implemented in 2 ways:

  1. Create a new interface e.g. bdd-arrow that would decorate the arrow function before sending fn to new Test.
  2. Add a new option e.g. mocha --context-argument that would change how runnable.fn is called.

@boneskull
Copy link
Contributor

@eight04 see #3399

@boneskull boneskull removed the status: accepting prs Mocha can use your help with this one! label May 30, 2018
@JoshuaKGoldberg
Copy link
Member

Yeah, this would be a pretty big change to Mocha that is already solved by at least one userland integration mentioned in this thread. Per #5027 we're not looking to do big shakeups any time soon.

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg added the status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior label Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title enhancement: new interface to support arrow functions 🚀 Feature: New interface to support arrow functions Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests

8 participants