diff --git a/docs/rules/no-typeerror-with-notthrows.md b/docs/rules/no-typeerror-with-notthrows.md index 885a5ceb..75202b0c 100644 --- a/docs/rules/no-typeerror-with-notthrows.md +++ b/docs/rules/no-typeerror-with-notthrows.md @@ -1,6 +1,6 @@ -# Prevent specifying error type in `t.notThrows()` +# No specifying error type in `t.notThrows()` -AVA will fail if error type is specified with `t.notThrows()`. +AVA will fail if error constructor is specified in the second argument of `t.notThrows()`. ## Fail diff --git a/rules/no-typeerror-with-notthrows.js b/rules/no-typeerror-with-notthrows.js index 7a1e031a..976d1660 100644 --- a/rules/no-typeerror-with-notthrows.js +++ b/rules/no-typeerror-with-notthrows.js @@ -27,11 +27,11 @@ const create = context => { const functionArgName = node.arguments[1].name; - if (calleeProperty === 'notThrows') { + if (calleeProperty === 'notThrows' || calleeProperty === 'notThrowsAsync') { if (errorNameRegex.test(functionArgName)) { context.report({ node, - message: 'Do not specify Error in t.notThrows()' + message: 'Do not specify an error constructor in the second argument of t.notThrows()' }); } } @@ -44,6 +44,7 @@ module.exports = { meta: { docs: { url: util.getDocsUrl(__filename) - } + }, + type: 'problem' } }; diff --git a/test/no-typeerror-with-notthrows.js b/test/no-typeerror-with-notthrows.js index 18879892..be0bab5a 100644 --- a/test/no-typeerror-with-notthrows.js +++ b/test/no-typeerror-with-notthrows.js @@ -8,27 +8,114 @@ const ruleTester = avaRuleTester(test, { } }); -const errors = [{ruleId: 'no-typerror-with-notthrows'}]; +const errors = [{ruleId: 'no-typeerror-with-notthrows'}]; const header = `const test = require('ava');\n`; // eslint-disable-line quotes ruleTester.run('no-typeerror-with-notthrows', rule, { valid: [ - `${header} test('some test',t => {t.notThrows(() => {t.pass();});});`, - `${header} test(t => {t.notThrows(() => {t.pass();});});`, - `${header} test(t => {t.throws(() => {t.pass();}, TypeError);});`, - `${header} test(t => {t.end(); })`, - `${header} test('some test',t => {t.notThrows(() => {t.pass();}, true);});`, - `${header} test('some test',t => {t.notThrows(() => {t.pass();}, 'some string');});`, - `${header} test('some test',t => {t.notThrows(() => {t.pass();}, {firstName:'some', lastName: 'object'});});` + `${header} + test('some test',t => { + t.notThrows(() => { + t.pass(); + }); + });`, + + `${header} + test(t => { + t.notThrows(() => { + t.pass(); + }); + });`, + + `${header} + test(t => { + t.throws(() => { + t.pass(); + }, TypeError); + });`, + + `${header} + test(t => { + t.end(); })`, + + `${header} + test('some test',t => { + t.notThrows(() => { + t.pass(); + }, true); + });`, + + `${header} + test('some test',t => { + t.notThrows(() => { + t.pass(); + }, 'some string'); + });`, + + `${header} + test('some test',t => { + t.notThrows(() => { + t.pass(); + }, {firstName:'some', lastName: 'object'}); + });`, + + `${header} + test('some test',t => { + t.notThrowsAsync(() => { + t.pass(); + }); + });`, + + `${header} + test(t => { + t.notThrowsAsync(() => { + t.pass(); + }); + });`, + + `${header} + test('some test',t => { + t.notThrowsAsync(() => { + t.pass(); + }, {firstName:'some', lastName: 'object'}); + });` ], invalid: [ { - code: `${header} test(t => {t.notThrows(() => {t.pass();}, TypeError);});`, + code: `${header} + test(t => { + t.notThrows(() => { + t.pass(); + }, TypeError); + });`, + errors + }, + { + code: `${header} + test('some test',t => { + t.notThrows(() => { + t.pass(); + }, TypeError); + });`, + errors + }, + { + code: `${header} + test(t => { + t.notThrowsAsync(() => { + t.pass(); + }, TypeError); + });`, errors }, { - code: `${header} test('some test',t => {t.notThrows(() => {t.pass();}, TypeError);});`, + code: `${header} + test('some test',t => { + t.notThrowsAsync(() => { + t.pass(); + }, TypeError); + });`, errors } ]