fix(editor): Use fake timers in useDebounce.test.ts to make the test less flaky (no-changelog) (#6029)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-04-20 12:22:54 +02:00 committed by GitHub
parent c3d19f52a2
commit 4037b3aeed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ import { useDebounceHelper } from '../useDebounce';
import { render, screen } from '@testing-library/vue';
describe('useDebounceHelper', () => {
const debounceTime = 200;
const debounceTime = 500;
const TestComponent = {
template: `
@ -23,6 +23,7 @@ describe('useDebounceHelper', () => {
},
},
setup() {
vitest.useFakeTimers();
const { callDebounced } = useDebounceHelper();
return {
callDebounced,
@ -52,7 +53,7 @@ describe('useDebounceHelper', () => {
expect(mockFn).toHaveBeenCalledTimes(0);
await new Promise((resolve) => setTimeout(resolve, debounceTime));
vitest.advanceTimersByTime(debounceTime);
expect(mockFn).toHaveBeenCalledTimes(1);
});