Skip to content

Commit

Permalink
fix(render): add default type for Queries parameter (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa authored Feb 2, 2021
1 parent 81c2de9 commit 5576e6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
* Render into a container which is appended to document.body. It should be used with cleanup.
*/
export function render<
Q extends Queries,
Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement
>(
ui: React.ReactElement,
Expand Down
16 changes: 16 additions & 0 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ export async function testWaitFor() {
await waitFor(() => {})
}

export function testQueries() {
const {getByLabelText} = render(
<label htmlFor="usernameInput">Username</label>,
)
expectType<HTMLElement, ReturnType<typeof getByText>>(
getByLabelText('Username'),
)

const container = document.createElement('div')
const options = {container}
const {getByText} = render(<div>Hello World</div>, options)
expectType<HTMLElement, ReturnType<typeof getByText>>(
getByText('Hello World'),
)
}

/*
eslint
testing-library/prefer-explicit-assert: "off",
Expand Down

0 comments on commit 5576e6f

Please sign in to comment.