ealush / vest

Vest ✅ Declarative validations framework
https://vestjs.dev/
MIT License
2.57k stars 85 forks source link

2024-03-30-debouce #1142

Closed ealush closed 8 months ago

ealush commented 8 months ago

| Related issues | #1057 1057 |

debounce()

The debounce() function in Vest helps you optimize function execution by introducing a delay. This is useful in scenarios where a function is called repeatedly due to user interaction, and you only want to execute the latest version after a period of inactivity.

Usage

1. Import Debounce

import debounce from 'vest/debounce';

2. Wrap your Test Callback:

test(
  'username',
  'User already taken',
  debounce(async () => {
    await doesUserExist();
  }, 2000),
);

In the above example, Vest will wait for two seconds before executing the test, and it will be run only once, no matter how many times the suite was invoked during this time period.

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2024 9:07pm
vest-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2024 9:07pm