• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7common.skipIfEslintMissing();
8
9const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
10const rule = require('../../tools/eslint-rules/prefer-assert-methods');
11
12new RuleTester().run('prefer-assert-methods', rule, {
13  valid: [
14    'assert.strictEqual(foo, bar);',
15    'assert(foo === bar && baz);',
16    'assert.notStrictEqual(foo, bar);',
17    'assert(foo !== bar && baz);',
18    'assert.equal(foo, bar);',
19    'assert(foo == bar && baz);',
20    'assert.notEqual(foo, bar);',
21    'assert(foo != bar && baz);',
22    'assert.ok(foo);',
23    'assert.ok(foo != bar);',
24    'assert.ok(foo === bar && baz);',
25  ],
26  invalid: [
27    {
28      code: 'assert(foo == bar);',
29      errors: [{
30        message: "'assert.equal' should be used instead of '=='"
31      }],
32      output: 'assert.equal(foo, bar);'
33    },
34    {
35      code: 'assert(foo === bar);',
36      errors: [{
37        message: "'assert.strictEqual' should be used instead of '==='"
38      }],
39      output: 'assert.strictEqual(foo, bar);'
40    },
41    {
42      code: 'assert(foo != bar);',
43      errors: [{
44        message: "'assert.notEqual' should be used instead of '!='"
45      }],
46      output: 'assert.notEqual(foo, bar);'
47    },
48    {
49      code: 'assert(foo !== bar);',
50      errors: [{
51        message: "'assert.notStrictEqual' should be used instead of '!=='"
52      }],
53      output: 'assert.notStrictEqual(foo, bar);'
54    },
55  ]
56});
57