-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: second round of bugfixes for v4 #314
Changes from all commits
755fc54
d58563d
eeab3b5
c96e948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
isImportSpecifier, | ||
isLiteral, | ||
isMemberExpression, | ||
isObjectPattern, | ||
isProperty, | ||
} from './node-utils'; | ||
import { | ||
|
@@ -582,16 +583,22 @@ export function detectTestingLibraryUtils< | |
// it could be "import * as rtl from 'baz'" | ||
return node.specifiers.find((n) => isImportNamespaceSpecifier(n)); | ||
} else { | ||
const requireNode = node.parent as TSESTree.VariableDeclarator; | ||
if (!ASTUtils.isVariableDeclarator(node.parent)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes problem A |
||
return undefined; | ||
} | ||
const requireNode = node.parent; | ||
|
||
if (ASTUtils.isIdentifier(requireNode.id)) { | ||
// this is const rtl = require('foo') | ||
return requireNode.id; | ||
} | ||
|
||
// this should be const { something } = require('foo') | ||
const destructuring = requireNode.id as TSESTree.ObjectPattern; | ||
const property = destructuring.properties.find( | ||
if (!isObjectPattern(requireNode.id)) { | ||
return undefined; | ||
} | ||
|
||
const property = requireNode.id.properties.find( | ||
(n) => | ||
isProperty(n) && | ||
ASTUtils.isIdentifier(n.key) && | ||
|
@@ -618,8 +625,18 @@ export function detectTestingLibraryUtils< | |
return userEventIdentifier.local; | ||
} | ||
} else { | ||
const requireNode = importedUserEventLibraryNode.parent as TSESTree.VariableDeclarator; | ||
return requireNode.id as TSESTree.Identifier; | ||
if ( | ||
!ASTUtils.isVariableDeclarator(importedUserEventLibraryNode.parent) | ||
) { | ||
return null; | ||
} | ||
|
||
const requireNode = importedUserEventLibraryNode.parent; | ||
if (!ASTUtils.isIdentifier(requireNode.id)) { | ||
return null; | ||
} | ||
|
||
return requireNode.id; | ||
} | ||
|
||
return null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,13 +58,12 @@ const domRules = { | |
'testing-library/no-wait-for-empty-callback': 'error', | ||
'testing-library/prefer-find-by': 'error', | ||
'testing-library/prefer-screen-queries': 'error', | ||
'testing-library/prefer-user-event': 'warn', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes problem B |
||
}; | ||
|
||
const angularRules = { | ||
...domRules, | ||
'testing-library/no-container': 'error', | ||
'testing-library/no-debug': 'warn', | ||
'testing-library/no-debug': 'error', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes problem C |
||
'testing-library/no-dom-import': ['error', 'angular'], | ||
'testing-library/no-node-access': 'error', | ||
'testing-library/render-result-naming-convention': 'error', | ||
|
@@ -73,7 +72,7 @@ const angularRules = { | |
const reactRules = { | ||
...domRules, | ||
'testing-library/no-container': 'error', | ||
'testing-library/no-debug': 'warn', | ||
'testing-library/no-debug': 'error', | ||
'testing-library/no-dom-import': ['error', 'react'], | ||
'testing-library/no-node-access': 'error', | ||
'testing-library/render-result-naming-convention': 'error', | ||
|
@@ -83,7 +82,7 @@ const vueRules = { | |
...domRules, | ||
'testing-library/await-fire-event': 'error', | ||
'testing-library/no-container': 'error', | ||
'testing-library/no-debug': 'warn', | ||
'testing-library/no-debug': 'error', | ||
'testing-library/no-dom-import': ['error', 'vue'], | ||
'testing-library/no-node-access': 'error', | ||
'testing-library/render-result-naming-convention': 'error', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we can generate this table automatically in the future from rules properties :)