node/test/parallel/test-eslint-prefer-assert-methods.js
Michaël Zasso 2eff28fb7a
tools: move ESLint to tools/eslint
Greatly simplify how ESLint and its plugins are installed.

PR-URL: https://github.com/nodejs/node/pull/53413
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-06-19 19:54:08 +00:00

58 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
if ((!common.hasCrypto) || (!common.hasIntl)) {
common.skip('ESLint tests require crypto and Intl');
}
common.skipIfEslintMissing();
const RuleTester = require('../../tools/eslint/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/prefer-assert-methods');
new RuleTester().run('prefer-assert-methods', rule, {
valid: [
'assert.strictEqual(foo, bar);',
'assert(foo === bar && baz);',
'assert.notStrictEqual(foo, bar);',
'assert(foo !== bar && baz);',
'assert.equal(foo, bar);',
'assert(foo == bar && baz);',
'assert.notEqual(foo, bar);',
'assert(foo != bar && baz);',
'assert.ok(foo);',
'assert.ok(foo != bar);',
'assert.ok(foo === bar && baz);',
],
invalid: [
{
code: 'assert(foo == bar);',
errors: [{
message: "'assert.equal' should be used instead of '=='"
}],
output: 'assert.equal(foo, bar);'
},
{
code: 'assert(foo === bar);',
errors: [{
message: "'assert.strictEqual' should be used instead of '==='"
}],
output: 'assert.strictEqual(foo, bar);'
},
{
code: 'assert(foo != bar);',
errors: [{
message: "'assert.notEqual' should be used instead of '!='"
}],
output: 'assert.notEqual(foo, bar);'
},
{
code: 'assert(foo !== bar);',
errors: [{
message: "'assert.notStrictEqual' should be used instead of '!=='"
}],
output: 'assert.notStrictEqual(foo, bar);'
},
]
});