• 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-iferror');
11
12new RuleTester().run('prefer-assert-iferror', rule, {
13  valid: [
14    'assert.ifError(err);',
15    'if (err) throw somethingElse;',
16    'throw err;',
17    'if (err) { throw somethingElse; }',
18  ],
19  invalid: [
20    {
21      code: 'require("assert");\n' +
22            'if (err) throw err;',
23      errors: [{ message: 'Use assert.ifError(err) instead.' }],
24      output: 'require("assert");\n' +
25              'assert.ifError(err);'
26    },
27    {
28      code: 'require("assert");\n' +
29            'if (error) { throw error; }',
30      errors: [{ message: 'Use assert.ifError(error) instead.' }],
31      output: 'require("assert");\n' +
32              'assert.ifError(error);'
33    },
34  ]
35});
36