Skip to content

Commit e121350

Browse files
thomaslombartBelco90
authored andcommitted
fix: immediately awaited assign to var (#9)
* fix: fix immediately awaited call assigned to var * feat: add test on pre-commit
1 parent 7026e6d commit e121350

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.huskyrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hooks": {
3-
"pre-commit": "lint-staged",
3+
"pre-commit": "npm run test && lint-staged",
44
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
55
}
66
}

lib/rules/await-async-query.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ module.exports = {
3030
const testingLibraryQueryUsage = [];
3131
return {
3232
[`CallExpression > Identifier[name=${ASYNC_QUERIES_REGEXP}]`](node) {
33-
testingLibraryQueryUsage.push(node);
33+
if (!isAwaited(node.parent.parent) && !isPromiseResolved(node)) {
34+
testingLibraryQueryUsage.push(node);
35+
}
3436
},
3537
'Program:exit'() {
3638
testingLibraryQueryUsage.forEach(node => {

tests/lib/rules/await-async-query.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ ruleTester.run('await-async-query', rule, {
4444
`,
4545
})),
4646

47+
// async queries saving element in var with promise immediately resolved are valid
48+
...ASYNC_QUERIES_COMBINATIONS.map(query => ({
49+
code: `async () => {
50+
doSomething()
51+
const foo = ${query}('foo').then(node => node)
52+
expect(foo).toBeInTheDocument();
53+
}
54+
`,
55+
})),
56+
4757
// async queries with promise in variable and await operator are valid
4858
...ASYNC_QUERIES_COMBINATIONS.map(query => ({
4959
code: `async () => {

0 commit comments

Comments
 (0)