summaryrefslogtreecommitdiff
path: root/test/parallel/test-eslint-prefer-assert-methods.js
blob: a5829cdce3054f5b57e96fc1bee03b9eadaaead7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'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);'
    }
  ]
});