Skip to content

Commit

Permalink
fix(no-debug): catch all screen imports (#175)
Browse files Browse the repository at this point in the history
Closes #174
  • Loading branch information
timdeschryver authored Jun 18, 2020
1 parent c3f9b34 commit 783ced0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/rules/no-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isLiteral,
isAwaitExpression,
isMemberExpression,
isImportSpecifier,
} from '../node-utils';

export const RULE_NAME = 'no-debug';
Expand Down Expand Up @@ -141,12 +142,11 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
},
// checks if import has shape:
// import { screen } from '@testing-library/dom';
'ImportDeclaration ImportSpecifier'(node: TSESTree.ImportSpecifier) {
const importDeclarationNode = node.parent as TSESTree.ImportDeclaration;

if (!hasTestingLibraryImportModule(importDeclarationNode)) return;

hasImportedScreen = node.imported.name === 'screen';
ImportDeclaration(node: TSESTree.ImportDeclaration) {
if (!hasTestingLibraryImportModule(node)) return;
hasImportedScreen = node.specifiers.some(
s => isImportSpecifier(s) && s.imported.name === 'screen'
);
},
// checks if import has shape:
// import * as dtl from '@testing-library/dom';
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/no-debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ ruleTester.run(RULE_NAME, rule, {
},
],
},
{
// https://github.com/testing-library/eslint-plugin-testing-library/issues/174
code: `
import { screen, render } from '@testing-library/dom'
screen.debug()
`,
errors: [
{
messageId: 'noDebug',
},
],
},
{
code: `
import * as dtl from '@testing-library/dom';
Expand Down

0 comments on commit 783ced0

Please sign in to comment.