Skip to content

Commit 5576e6f

Browse files
authoredFeb 2, 2021
fix(render): add default type for Queries parameter (#871)
1 parent 81c2de9 commit 5576e6f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
4747
* Render into a container which is appended to document.body. It should be used with cleanup.
4848
*/
4949
export function render<
50-
Q extends Queries,
50+
Q extends Queries = typeof queries,
5151
Container extends Element | DocumentFragment = HTMLElement
5252
>(
5353
ui: React.ReactElement,

‎types/test.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ export async function testWaitFor() {
8484
await waitFor(() => {})
8585
}
8686

87+
export function testQueries() {
88+
const {getByLabelText} = render(
89+
<label htmlFor="usernameInput">Username</label>,
90+
)
91+
expectType<HTMLElement, ReturnType<typeof getByText>>(
92+
getByLabelText('Username'),
93+
)
94+
95+
const container = document.createElement('div')
96+
const options = {container}
97+
const {getByText} = render(<div>Hello World</div>, options)
98+
expectType<HTMLElement, ReturnType<typeof getByText>>(
99+
getByText('Hello World'),
100+
)
101+
}
102+
87103
/*
88104
eslint
89105
testing-library/prefer-explicit-assert: "off",

0 commit comments

Comments
 (0)
Please sign in to comment.