lo1tuma / eslint-plugin-mocha

ESLint rules for mocha
MIT License
279 stars 61 forks source link

handle-done-callback: wrongly detect done callback #205

Open VinhVu0412 opened 5 years ago

VinhVu0412 commented 5 years ago

I am using nightwatch with mocha, my test function look like this

it('uses BDD to run the Google simple test', function(browser) {
  browser
    .url('http://google.com')
    .expect.element('body').to.be.present.before(1000);

  browser.setValue('input[type=text]', ['nightwatch', browser.Keys.ENTER])
    .pause(1000)
    .assert.containsText('#main', 'Night Watch');
});

(More detail about using mocha with nightwatch is here)

When I check with eslint, it says error Expected "browser" callback to be handled mocha/handle-done-callback

I am using

{
  "nightwatch": "^1.1.13",
  "mocha": "^6.2.0",
  "eslint": "^6.1.0",
  "eslint-plugin-mocha": "^6.0.0"
}

The checker thinks browser is done callback, but it's not.

lo1tuma commented 5 years ago

Mocha always expects the done callback parameter to be the first argument. The behavior of injecting the browser parameter is added by nightwatch and is not compatible with the default behavior of mocha.

That’s being said, I would be open for a change proposal that solves this kind of issues in a generic way (i.e. not nightwatch specific). Maybe something like adding a configuration option that allows you to specify the expected argument position.

VinhVu0412 commented 5 years ago

That sounds great. At this point of time, I'll stay with inline ignore.