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

feat: advanceTimers callback #585

Closed
ph-fritsche opened this issue Mar 17, 2021 · 2 comments · Fixed by #907
Closed

feat: advanceTimers callback #585

ph-fritsche opened this issue Mar 17, 2021 · 2 comments · Fixed by #907
Labels
enhancement New feature or request

Comments

@ph-fritsche
Copy link
Member

@ph-fritsche - Would it be possible to add an advance option to type?
The typeImpl function could then call that with the delay before await ing on the promise.

As an example of the approach, I'm using this "wrapper" around type (it only works for plaintext):

async function typeWithDelay(input, text, delayInMilliseconds) {
  let previous = Promise.resolve();
  for (const codepoint of text) {
    await previous;
    userEvent.type(input, codepoint);

    previous = new Promise((resolve) => setTimeout(() => resolve(), delayInMilliseconds));

    act(() => {
      jest.advanceTimersByTime(delayInMilliseconds);
    });
  }
}

So instead of above, I could just call userEvent.type(input, 'some text', { delay: 20, advance: jest.advanceTimersByTime });

Originally posted by @icedtoast in #565 (comment)

@ph-fritsche
Copy link
Member Author

@all-contributors add @icedtoast ideas

@allcontributors
Copy link
Contributor

@ph-fritsche

I've put up a pull request to add @icedtoast! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant