Skip to content

Commit b38689c

Browse files
thomaslombartBelco90
authored andcommitted
test: reach 100% code coverage (#35)
1 parent 1126c23 commit b38689c

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

lib/rules/await-async-query.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,16 @@ module.exports = {
3636
},
3737
'Program:exit'() {
3838
testingLibraryQueryUsage.forEach(node => {
39-
const variableDeclaratorParent = findParent(
40-
node,
41-
parent => parent.type === 'VariableDeclarator'
42-
);
39+
const variableDeclaratorParent = node.parent.parent;
4340

4441
const references =
45-
(variableDeclaratorParent &&
46-
context
47-
.getDeclaredVariables(variableDeclaratorParent)[0]
48-
.references.slice(1)) ||
49-
[];
42+
variableDeclaratorParent.type === 'VariableDeclarator' &&
43+
context
44+
.getDeclaredVariables(variableDeclaratorParent)[0]
45+
.references.slice(1);
5046

5147
if (
48+
references &&
5249
references.length === 0 &&
5350
!isAwaited(node.parent.parent) &&
5451
!isPromiseResolved(node)
@@ -103,12 +100,3 @@ function isPromiseResolved(node) {
103100
// promise.then(...)
104101
return hasAThenProperty(parent);
105102
}
106-
107-
function findParent(node, check) {
108-
if (check(node)) {
109-
return node;
110-
} else if (node.parent) {
111-
return findParent(node.parent, check);
112-
}
113-
return null;
114-
}

lib/rules/await-fire-event.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ function isPromiseResolved(node) {
1414
const parent = node.parent.parent;
1515

1616
// fireEvent.click().then(...)
17-
if (parent.type === 'CallExpression') {
18-
return hasThenProperty(parent.parent);
19-
}
17+
return parent.type === 'CallExpression' && hasThenProperty(parent.parent);
2018
}
2119

2220
const VALID_PARENTS = [

tests/lib/rules/prefer-expect-query-by.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ruleTester.run('prefer-expect-query-by', rule, {
2525
(validRules, queryName) => [
2626
...validRules,
2727
{ code: `expect(${queryName}('Hello')).toBeInTheDocument()` },
28+
{ code: `expect(${queryName}).toBeInTheDocument()` },
2829
{ code: `expect(rendered.${queryName}('Hello')).toBeInTheDocument()` },
2930
{ code: `expect(${queryName}('Hello')).not.toBeInTheDocument()` },
3031
{

0 commit comments

Comments
 (0)