Show an errror when using arrow functions with hooks
See original GitHub issueHi,
Today I’ve tried to use this.skip()
inside before()
it()
but it didn’t work because I was using arrow functions instead of normal functions and so this
was undefined.
It took me some time before being able to make this.skip()
works, and I think creating a rule can save time from other people too.
This rule would be recommended and will throw an error when using arrow functions with :
- describe, context
- it, it.skip, it.only, … specify
- before/beforeEach
- after/afterEach
What do you think? I can open a PR for this rule (I’ve never write an ESLint rule but it does not seems really complicated)
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Can't call useState hook in arrow function - Stack Overflow
I keep getting these errors: Line 6:33: React Hook "useState" is called in function "game" which is neither a React function component or...
Read more >How to use useState in arrow function instead of hook
It is a hook that takes the initial state as an argument and returns an array of two entries. It can be used...
Read more >Use ES6 Arrow Functions to Resolve "TypeError - Pluralsight
To do this, you can use ES6 arrow functions. Apart from making your code more succinct and readable, arrow functions serve another purpose....
Read more >Rules of Hooks - React
Only Call Hooks at the Top Level ... Don't call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the...
Read more >Synchronous code, arrow functions and hooks - mocha
You can invoke any hook with an optional description, this makes it easier to pinpoint errors in your tests. If you give a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Instead of erroring always when you use an arrow function with
describe
,it
, etc, I would rather it error only if you use an arrow function and then usethis
inside the function body.Bonus points if it could auto-fix by converting the arrow function into a regular function in that case.
Btw, FWIW, some other nice Mocha plugins:
And chai ones: