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.

Mocha tests: Missing function expression name. (func-names)

See original GitHub issue

When writing Mocha tests, it is not possible to use fat arrow functions because we sometimes need to use the this keyword to change the test’s timeout for example.

describe('some description', function () {
  before('blabla', function () {
    this.timeout(10000);
    return somePromise();
  });
});

This results in the following eslint error:

Missing function expression name. (func-names)

I was wondering what was the guidelines for this case. Naming the functions is out of the question as it would add a lot of noise.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16

github_iconTop GitHub Comments

3reactions
LeopoldoFucommented, Nov 1, 2016

Using arrow functions in mocha tests is discouraged according to their official documentation.

3reactions
olalondecommented, Apr 16, 2017

I just don’t really see the point for mocha tests and it goes against the DRY principle. e.g.

    it('should return status 200', function shouldReturnStatus200() {
      expect(self.res.status).to.equal(200);
    });

Anyways, I added func-names: 0 to my tests/.eslintrc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning Unexpected unnamed function func-names under ...
ESLint is complaining about this line, which is indeed an expression, not an assignment or function call: !hash[curr.farmerId] && (hash[curr ...
Read more >
func-names - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run ......
Read more >
How to test JavaScript with Mocha — Part 2 - codeburst
We're going to test to ensure these functions are working nicely. Here's the structure I see our test.js file taking: A testing group...
Read more >
ValidateJavaScript - Online Tool to Find & Fix JavaScript Errors
func-names func-style function-call-argument-newline function-paren-newline generator-star-spacing getter-return ... no-unused-expressions no-unused-labels
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