|
| 1 | +import test from 'ava'; |
| 2 | +import avaRuleTester from 'eslint-ava-rule-tester'; |
| 3 | +import rule from '../rules/no-async-fn-without-await'; |
| 4 | + |
| 5 | +const ruleTester = avaRuleTester(test, { |
| 6 | + parser: 'babel-eslint', |
| 7 | + env: { |
| 8 | + es6: true |
| 9 | + } |
| 10 | +}); |
| 11 | + |
| 12 | +const error = { |
| 13 | + ruleId: 'no-async-fn-without-await', |
| 14 | + message: 'Function was declared as `async` but doesn\'t use `await`' |
| 15 | +}; |
| 16 | +const header = `const test = require('ava');\n`; |
| 17 | + |
| 18 | +ruleTester.run('no-async-fn-without-await', rule, { |
| 19 | + valid: [ |
| 20 | + `${header} test(fn);`, |
| 21 | + `${header} test(t => {});`, |
| 22 | + `${header} test(function(t) {});`, |
| 23 | + `${header} test(async t => { await foo(); });`, |
| 24 | + `${header} test(async t => { t.is(await foo(), 1); });`, |
| 25 | + `${header} test(async function(t) { await foo(); });`, |
| 26 | + `${header} test(async t => { if (bar) { await foo(); } });`, |
| 27 | + `${header} test(async t => { if (bar) {} else { await foo(); } });`, |
| 28 | + // shouldn't be triggered since it's not a test file |
| 29 | + 'test(async t => {});' |
| 30 | + ], |
| 31 | + invalid: [ |
| 32 | + { |
| 33 | + code: `${header} test(async t => {});`, |
| 34 | + errors: [error] |
| 35 | + }, |
| 36 | + { |
| 37 | + code: `${header} test(async function(t) {});`, |
| 38 | + errors: [error] |
| 39 | + }, |
| 40 | + { |
| 41 | + code: `${header} test(async t => {}); test(async t => {});`, |
| 42 | + errors: [error, error] |
| 43 | + }, |
| 44 | + { |
| 45 | + code: `${header} test(async t => {}); test(async t => { await foo(); });`, |
| 46 | + errors: [error] |
| 47 | + }, |
| 48 | + { |
| 49 | + code: `${header} test(async t => { await foo(); }); test(async t => {});`, |
| 50 | + errors: [error] |
| 51 | + } |
| 52 | + ] |
| 53 | +}); |
0 commit comments