• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5common.skipIfEslintMissing();
6
7const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
8const rule = require('../../tools/eslint-rules/async-iife-no-unused-result');
9
10const message = 'The result of an immediately-invoked async function needs ' +
11  'to be used (e.g. with `.then(common.mustCall())`)';
12
13const tester = new RuleTester({ parserOptions: { ecmaVersion: 8 } });
14tester.run('async-iife-no-unused-result', rule, {
15  valid: [
16    '(() => {})()',
17    '(async () => {})',
18    '(async () => {})().then()',
19    '(async () => {})().catch()',
20    '(function () {})()',
21    '(async function () {})',
22    '(async function () {})().then()',
23    '(async function () {})().catch()',
24  ],
25  invalid: [
26    {
27      code: '(async () => {})()',
28      errors: [{ message }],
29      output: '(async () => {})()',
30    },
31    {
32      code: '(async function() {})()',
33      errors: [{ message }],
34      output: '(async function() {})()',
35    },
36    {
37      code: "const common = require('../common');(async () => {})()",
38      errors: [{ message }],
39      output: "const common = require('../common');(async () => {})()" +
40        '.then(common.mustCall())',
41    },
42    {
43      code: "const common = require('../common');(async function() {})()",
44      errors: [{ message }],
45      output: "const common = require('../common');(async function() {})()" +
46        '.then(common.mustCall())',
47    },
48  ]
49});
50