Skip to content

Commit

Permalink
fix(browser): don't release keyboard automatically (#6083)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jul 10, 2024
1 parent ee72518 commit 58fac77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/browser/src/node/commands/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const keyboard: UserEventCommand<UserEvent['keyboard']> = async (
throw new TypeError(`Provider "${context.provider.name}" does not support selecting all text`)
}
},
false,
true,
)
}

Expand Down
16 changes: 16 additions & 0 deletions test/browser/test/userEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ describe('userEvent.keyboard', async () => {
])
})

test('should not auto release', async () => {
const spyKeydown = vi.fn()
const spyKeyup = vi.fn()
const button = document.createElement('button')
document.body.appendChild(button)
button.addEventListener('keydown', spyKeydown)
button.addEventListener('keyup', spyKeyup)
button.focus()
await userEvent.keyboard('{Enter>}')
expect(spyKeydown).toHaveBeenCalledOnce()
expect(spyKeyup).not.toHaveBeenCalled()
await userEvent.keyboard('{/Enter}')
// userEvent doesn't fire any event here, but should we?
expect(spyKeyup).not.toHaveBeenCalled()
})

test('standalone keyboard works correctly with active input', async () => {
const documentKeydown: string[] = []
const inputKeydown: string[] = []
Expand Down

0 comments on commit 58fac77

Please sign in to comment.