Skip to content

Commit

Permalink
fix(no-focused-tests): detect usage like 'test.only.each()'
Browse files Browse the repository at this point in the history
  • Loading branch information
msvab authored and SimenB committed Oct 2, 2018
1 parent 9ea1f78 commit 4e4313e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
12 changes: 12 additions & 0 deletions rules/__tests__/no-focused-tests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ruleTester.run('no-focused-tests', rule, {
code: 'describe.only()',
errors: [{ message: expectedErrorMessage, column: 10, line: 1 }],
},
{
code: 'describe.only.each()',
errors: [{ message: expectedErrorMessage, column: 10, line: 1 }],
},
{
code: 'describe["only"]()',
errors: [{ message: expectedErrorMessage, column: 10, line: 1 }],
Expand All @@ -31,6 +35,10 @@ ruleTester.run('no-focused-tests', rule, {
code: 'it.only()',
errors: [{ message: expectedErrorMessage, column: 4, line: 1 }],
},
{
code: 'it.only.each()',
errors: [{ message: expectedErrorMessage, column: 4, line: 1 }],
},
{
code: 'it["only"]()',
errors: [{ message: expectedErrorMessage, column: 4, line: 1 }],
Expand All @@ -39,6 +47,10 @@ ruleTester.run('no-focused-tests', rule, {
code: 'test.only()',
errors: [{ message: expectedErrorMessage, column: 6, line: 1 }],
},
{
code: 'test.only.each()',
errors: [{ message: expectedErrorMessage, column: 6, line: 1 }],
},
{
code: 'test["only"]()',
errors: [{ message: expectedErrorMessage, column: 6, line: 1 }],
Expand Down
28 changes: 19 additions & 9 deletions rules/no-focused-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ module.exports = {
CallExpression(node) {
const callee = node.callee;

if (
callee.type === 'MemberExpression' &&
isCallToTestOnlyFunction(callee)
) {
context.report({
message: 'Unexpected focused test.',
node: callee.property,
});
return;
if (callee.type === 'MemberExpression') {
if (
callee.object.type === 'MemberExpression' &&
isCallToTestOnlyFunction(callee.object)
) {
context.report({
message: 'Unexpected focused test.',
node: callee.object.property,
});
return;
}

if (isCallToTestOnlyFunction(callee)) {
context.report({
message: 'Unexpected focused test.',
node: callee.property,
});
return;
}
}

if (callee.type === 'Identifier' && isCallToFocusedTestFunction(callee)) {
Expand Down

0 comments on commit 4e4313e

Please # to comment.