question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show an errror when using arrow functions with hooks

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
chrisbreidingcommented, Nov 15, 2019

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 use this inside the function body.

Bonus points if it could auto-fix by converting the arrow function into a regular function in that case.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found