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

#1020 Update mochajs snippets to use old functions #1021

Closed
wants to merge 1 commit into from

Conversation

hovissimo
Copy link

@lpil
Copy link
Contributor

lpil commented Jan 26, 2018

Hi @hovissimo. Why do you want to make this change? The only versions of node that do not support this are no longer supported

Copy link
Contributor

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending

@hovissimo
Copy link
Author

@lpil

See mochajs/mocha#2018 from the PR description.

Fat arrows are specifically discouraged for Mocha JS because Mocha JS uses 'this' for test context. The lexical binding of the fat arrows syntax prevents that.

@lpil
Copy link
Contributor

lpil commented Dec 12, 2018

Thanks for the link, very helpful.

There's reason to use the long-form function syntax, but in the wild I've only seen the arrow syntax used, so it seems there's a split here. I think it'd be good to make this configurable by the user, they can set a value indicating which to use.

I'd like to default to the arrow to match existing behaviour.

@Pompeu
Copy link
Contributor

Pompeu commented Feb 11, 2019

@lpil

See mochajs/mocha#2018 from the PR description.

Fat arrows are specifically discouraged for Mocha JS because Mocha JS uses 'this' for test context. The lexical binding of the fat arrows syntax prevents that.

You can use config file of mocha, and dont need use "this".

@hovissimo
Copy link
Author

@Pompeu I don't see how any options in the config file change the lexical binding of test blocks. Can you point to exactly what you mean?

I maintain that if this project is going to maintain snippets for a specific testing library it should conform to that library's most general recommendations. Further, I find fat arrows for the sake of consistency to be a weak argument, because fat arrows are in no way replacing the old function declaration. They're a new and different kind of function declaration per the ES spec. One does one thing (methods), the other does another (subroutines/procedures) and the right tool should be used for the job. In this case these are methods and NOT subroutines and the authors of mochajs picked methods in particular and documented their decision (and included a specific warning against arrow functions!).

That said, it's your project and I've already forked it for my use so /shrug.

@lpil
Copy link
Contributor

lpil commented Mar 1, 2019

Closing due to inactivity. Please re-open if you'd like to continue. Thank you! :)

@lpil lpil closed this Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants