简体   繁体   中英

Override error message on eslint-plugin-mocha rule

I'm using eslint-plugin-mocha to put some rules on writing tests with mocha and here is what my .eslintrc.js file looks like

module.exports = {
  root: true,
  parserOptions: {
    sourceType: 'module'
  },
  plugins: ['mocha'],
  extends: 'plugin:mocha/recommended',
  rules: {
    'mocha/valid-test-description': ['error', /^should/]
  },
  env: {
    'mocha': true
  }
}

This rule finds any test description that doesn't start with should . The error message looks like that

error  Invalid "it()" description found  mocha/valid-test-description

I'd like the change this error message to be more descriptive but the rule doesn't offer options to change this message. Do you know how with eslint to configure this ?

I've made a PR and this feature is available since version 6.1.0 of eslint-plugin-mocha .

Here is how to define the error message:

rules: {
  'mocha/valid-test-description': ['error', { pattern: /^should/, message: 'Should start with "should"' }]
}
// OR
rules: {
  'mocha/valid-test-description': ['error', /^should/, ['it', 'specify', 'test'], 'Should start with "should"']
}

The documentation is available here .

Now the error message is:

error  Should start with "should"  mocha/valid-test-description

Note: the same feature is available for the valid-suite-description rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM