node/test/parallel/test-eslint-prefer-assert-methods.js
Rich Trott 330f25ef82 test: prepare for consistent comma-dangle lint rule
Make changes so that tests will pass when the comma-dangle settings
applied to the rest of the code base are also applied to tests.

PR-URL: https://github.com/nodejs/node/pull/37930
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
2021-04-01 23:14:29 -07:00

56 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
common.skipIfEslintMissing();
const RuleTester = require('../../tools/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);'
},
]
});