Skip to content

Commit bf17498

Browse files
committed
fix: keyboard types are now correct
1 parent d2c0b62 commit bf17498

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/user-event/keyboard/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@ export type {keyboardOptions, keyboardKey}
99
export function keyboard(
1010
instance: TestInstance,
1111
text: string,
12-
options?: Partial<keyboardOptions & {delay: 0}>,
13-
): void
14-
export function keyboard(
15-
instance: TestInstance,
16-
text: string,
17-
options: Partial<
18-
keyboardOptions & {delay: number}
19-
>,
20-
): Promise<void>
21-
export function keyboard(
22-
instance: TestInstance,
23-
text: string,
24-
options?: Partial<keyboardOptions>,
12+
options?: Partial<keyboardOptions & {delay: number}>,
2513
): void | Promise<void> {
2614
const {promise} = keyboardImplementationWrapper(instance, text, options)
2715

types/__tests__/type-tests.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BoundFunctions
66
} from 'cli-testing-library'
77
import {render, TestInstance} from "../pure";
8+
import userEvent from "../../src/user-event";
89

910
const {
1011
getByText,
@@ -46,6 +47,16 @@ export async function eventTest() {
4647
fireEvent.write(instance, {value: 'test'});
4748
}
4849

50+
export async function keyboardTest() {
51+
const instance = await render('command', []);
52+
53+
userEvent.keyboard(instance, "Test")
54+
instance.userEvent.keyboard("Test")
55+
await instance.userEvent.keyboard("Test", {delay: 0})
56+
57+
fireEvent.write(instance, {value: 'test'});
58+
}
59+
4960
export async function testWaitFors() {
5061
const instance = await render('command', []);
5162

types/pure.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {SpawnOptionsWithoutStdio} from 'child_process'
22
import {ChildProcess} from 'node:child_process'
33
import type userEvent from '../src/user-event'
4-
import type {queries, BoundFunction} from './get-queries-for-instance'
4+
import type {queries, BoundFunction, BoundFunctions} from './get-queries-for-instance'
55

66
export interface TestInstance {
77
clear(): void
@@ -21,12 +21,12 @@ export interface RenderOptions {
2121
spawnOpts: Omit<SpawnOptionsWithoutStdio, 'cwd'>
2222
}
2323

24+
type UserEvent = typeof userEvent;
25+
2426
export type RenderResult = TestInstance & {
25-
userEvent: ReturnType<
26-
{
27-
[key in keyof typeof userEvent]: BoundFunction<typeof userEvent[key]>
28-
}
29-
>
27+
userEvent: {
28+
[P in keyof UserEvent]: BoundFunction<UserEvent[P]>
29+
}
3030
} & {[P in keyof typeof queries]: BoundFunction<typeof queries[P]>}
3131

3232
export function render(

0 commit comments

Comments
 (0)