]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-async-promise-executor.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / no-async-promise-executor.js
1 /**
2 * @fileoverview disallow using an async function as a Promise executor
3 * @author Teddy Katz
4 */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Requirements
9 //------------------------------------------------------------------------------
10
11 const rule = require("../../../lib/rules/no-async-promise-executor");
12 const { RuleTester } = require("../../../lib/rule-tester");
13
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8 } });
20
21 ruleTester.run("no-async-promise-executor", rule, {
22
23 valid: [
24 "new Promise((resolve, reject) => {})",
25 "new Promise((resolve, reject) => {}, async function unrelated() {})",
26 "new Foo(async (resolve, reject) => {})"
27 ],
28
29 invalid: [
30 {
31 code: "new Promise(async function foo(resolve, reject) {})",
32 errors: [{
33 messageId: "async",
34 line: 1,
35 column: 13,
36 endLine: 1,
37 endColumn: 18
38 }]
39 },
40 {
41 code: "new Promise(async (resolve, reject) => {})",
42 errors: [{
43 messageId: "async",
44 line: 1,
45 column: 13,
46 endLine: 1,
47 endColumn: 18
48 }]
49 },
50 {
51 code: "new Promise(((((async () => {})))))",
52 errors: [{
53 messageId: "async",
54 line: 1,
55 column: 17,
56 endLine: 1,
57 endColumn: 22
58 }]
59 }
60 ]
61 });