Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rahgurung committed May 14, 2019
1 parent 41fafa4 commit 2d86d15
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/rules/no-typeerror-with-notthrows.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions rules/no-typeerror-with-notthrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
});
}
}
Expand All @@ -44,6 +44,7 @@ module.exports = {
meta: {
docs: {
url: util.getDocsUrl(__filename)
}
},
type: 'problem'
}
};
107 changes: 97 additions & 10 deletions test/no-typeerror-with-notthrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
Expand Down

0 comments on commit 2d86d15

Please sign in to comment.