Skip to content

Commit c1bf047

Browse files
fix(TS): Forbid async function as callback argument for waitFor (#572)
* fix(TS): Forbid async function as callback argument for waitFor * fix(TS): Add tests for passing an async function to waitFor * feat: Update kcd-scripts
1 parent 8846eaf commit c1bf047

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"jest-serializer-ansi": "^1.0.3",
5151
"jest-watch-select-projects": "^2.0.0",
5252
"jsdom": "^16.2.2",
53-
"kcd-scripts": "^6.0.0"
53+
"kcd-scripts": "^6.2.0"
5454
},
5555
"eslintConfig": {
5656
"extends": "./node_modules/kcd-scripts/eslint.js",

types/__tests__/type-tests.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
waitFor,
99
waitForElementToBeRemoved,
1010
MatcherOptions,
11-
} from '../index'
11+
} from '@testing-library/dom'
1212

1313
const {
1414
getByText,
@@ -162,4 +162,7 @@ async function testWaitFors() {
162162
})
163163
await waitForElementToBeRemoved(getByText(element, 'apple'))
164164
await waitForElementToBeRemoved(getAllByText(element, 'apple'))
165+
166+
// $ExpectError
167+
await waitFor(async () => {})
165168
}

types/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"strictNullChecks": true,
1010
"strictFunctionTypes": true,
1111
"noEmit": true,
12-
13-
// If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index".
14-
// If the library is global (cannot be imported via `import` or `require`), leave this out.
15-
"baseUrl": "."
12+
"baseUrl": ".",
13+
"paths": {"@testing-library/dom": ["."]}
1614
}
1715
}

types/wait-for.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export interface waitForOptions {
2-
container?: HTMLElement;
3-
timeout?: number;
4-
interval?: number;
5-
mutationObserverOptions?: MutationObserverInit;
2+
container?: HTMLElement
3+
timeout?: number
4+
interval?: number
5+
mutationObserverOptions?: MutationObserverInit
66
}
77

88
export function waitFor<T>(
9-
callback: () => T,
10-
options?: waitForOptions,
11-
): Promise<T>;
9+
callback: () => T extends Promise<any> ? never : T,
10+
options?: waitForOptions,
11+
): Promise<T>

0 commit comments

Comments
 (0)