mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
fix(editor): Use fake timers in useDebounce.test.ts to make the test less flaky (no-changelog) (#6029)
This commit is contained in:
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);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue