Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update delay document and add test confirming the delay behavior #1175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/options.ts
Expand Up @@ -37,7 +37,7 @@ export interface Options {

/**
* Between some subsequent inputs like typing a series of characters
* the code execution is delayed per `setTimeout` for (at least) `delay` seconds.
* the code execution is delayed per `setTimeout` for (at least) `delay` milliseconds.
* This moves the next changes at least to next macro task
* and allows other (asynchronous) code to run between events.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/keyboard/index.ts
Expand Up @@ -127,6 +127,17 @@ describe('delay', () => {
expect(time0).toBeLessThan(performance.now() - 20)
})

test('delay keyboard 100 milliseconds between keydowns', async () => {
const {user} = setup('', {delay: 100})

const startTimer = performance.now()
await user.keyboard('foo')
const endTimer = performance.now()

expect(setTimeout).toHaveBeenCalledTimes(4)
expect(endTimer - startTimer).toBeGreaterThan(400)
})

test('do not call setTimeout with delay `null`', async () => {
const {user} = setup('', {delay: null})
await user.keyboard('foo')
Expand Down