mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(editor): Use fake timers in useDebounce.test.ts to make the test less flaky (no-changelog) (#6029)
This commit is contained in:
committed by
GitHub
parent
c3d19f52a2
commit
4037b3aeed
@@ -3,7 +3,7 @@ import { useDebounceHelper } from '../useDebounce';
|
|||||||
import { render, screen } from '@testing-library/vue';
|
import { render, screen } from '@testing-library/vue';
|
||||||
|
|
||||||
describe('useDebounceHelper', () => {
|
describe('useDebounceHelper', () => {
|
||||||
const debounceTime = 200;
|
const debounceTime = 500;
|
||||||
|
|
||||||
const TestComponent = {
|
const TestComponent = {
|
||||||
template: `
|
template: `
|
||||||
@@ -23,6 +23,7 @@ describe('useDebounceHelper', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
|
vitest.useFakeTimers();
|
||||||
const { callDebounced } = useDebounceHelper();
|
const { callDebounced } = useDebounceHelper();
|
||||||
return {
|
return {
|
||||||
callDebounced,
|
callDebounced,
|
||||||
@@ -52,7 +53,7 @@ describe('useDebounceHelper', () => {
|
|||||||
|
|
||||||
expect(mockFn).toHaveBeenCalledTimes(0);
|
expect(mockFn).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, debounceTime));
|
vitest.advanceTimersByTime(debounceTime);
|
||||||
|
|
||||||
expect(mockFn).toHaveBeenCalledTimes(1);
|
expect(mockFn).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user