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