Skip to content

Commit

Permalink
Debounce default export
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Apr 1, 2024
1 parent be4060f commit a1f87be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/vest/src/exports/__tests__/debounce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import wait from 'wait';

import { TestFnPayload } from 'TestTypes';
import * as vest from 'vest';
import { debounce } from 'vest/debounce';
import debounce from 'vest/debounce';

describe('debounce', () => {
describe('Sync test', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/exports/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TestFn, TestFnPayload } from 'TestTypes';

const isolateType = 'Debounce';

export function debounce<Callback extends CB = CB>(
export default function debounce<Callback extends CB = CB>(
callback: Callback,
delay: number = 0,
): TestFn {
Expand Down
13 changes: 8 additions & 5 deletions website/docs/writing_tests/advanced_test_features/debounce.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ keywords: [Vest, debounce, async, test]

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**

```js
import {debounce} from 'vest/debounce';
import debounce from 'vest/debounce';
```

**2. Wrap your Test Callback:**

```js
test('username', 'User already taken', debounce(async () => {
test(
'username',
'User already taken',
debounce(async () => {
await doesUserExist();
}, 2000));
}, 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.
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.

0 comments on commit a1f87be

Please sign in to comment.