summaryrefslogtreecommitdiff
path: root/test/parallel/test-eslint-async-iife-no-unused-result.js
blob: 6e7f60c183b830a8bd682258a62fa621ecb0c919 (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
'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/async-iife-no-unused-result');

const message = 'The result of an immediately-invoked async function needs ' +
  'to be used (e.g. with `.then(common.mustCall())`)';

const tester = new RuleTester({ parserOptions: { ecmaVersion: 8 } });
tester.run('async-iife-no-unused-result', rule, {
  valid: [
    '(() => {})()',
    '(async () => {})',
    '(async () => {})().then()',
    '(async () => {})().catch()',
    '(function () {})()',
    '(async function () {})',
    '(async function () {})().then()',
    '(async function () {})().catch()',
  ],
  invalid: [
    {
      code: '(async () => {})()',
      errors: [{ message }],
      output: '(async () => {})()',
    },
    {
      code: '(async function() {})()',
      errors: [{ message }],
      output: '(async function() {})()',
    },
    {
      code: "const common = require('../common');(async () => {})()",
      errors: [{ message }],
      output: "const common = require('../common');(async () => {})()" +
        '.then(common.mustCall())',
    },
    {
      code: "const common = require('../common');(async function() {})()",
      errors: [{ message }],
      output: "const common = require('../common');(async function() {})()" +
        '.then(common.mustCall())',
    },
  ]
});