node/test/parallel/test-eslint-prefer-assert-iferror.js
Teddy Katz cd5ee52d70
test: add tests for eslint rules
This adds tests for the custom eslint rules in this repository, using
the `RuleTester` test utility bundled with eslint.

PR-URL: https://github.com/nodejs/node/pull/16138
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-14 02:53:19 -04:00

26 lines
619 B
JavaScript

'use strict';
require('../common');
const RuleTester = require('../../tools/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/prefer-assert-iferror');
new RuleTester().run('prefer-assert-iferror', rule, {
valid: [
'assert.ifError(err);',
'if (err) throw somethingElse;',
'throw err;',
'if (err) { throw somethingElse; }'
],
invalid: [
{
code: 'if (err) throw err;',
errors: [{ message: 'Use assert.ifError(err) instead.' }]
},
{
code: 'if (error) { throw error; }',
errors: [{ message: 'Use assert.ifError(error) instead.' }]
}
]
});