Chore: fix flaky unit test (#98102)

fix flaky unit test
This commit is contained in:
Ashley Harrison 2024-12-17 15:32:54 +00:00 committed by GitHub
parent 77fafd887a
commit 9c6b86958c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,5 @@
import { waitFor } from '@testing-library/react';
import { DataFrameView } from '@grafana/data'; import { DataFrameView } from '@grafana/data';
import { locationService } from '@grafana/runtime'; import { locationService } from '@grafana/runtime';
@ -33,6 +35,14 @@ describe('SearchStateManager', () => {
view: new DataFrameView<DashboardQueryResult>({ fields: [], length: 0 }), view: new DataFrameView<DashboardQueryResult>({ fields: [], length: 0 }),
}); });
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
it('Can get search state manager with initial state', async () => { it('Can get search state manager with initial state', async () => {
const stm = getSearchStateManager(); const stm = getSearchStateManager();
expect(stm.state.layout).toBe(SearchLayout.Folders); expect(stm.state.layout).toBe(SearchLayout.Folders);
@ -115,9 +125,9 @@ describe('SearchStateManager', () => {
stm.onQueryChange('debugging'); stm.onQueryChange('debugging');
await wait(150); jest.advanceTimersByTime(150);
expect(stm.state.result?.totalRows).toEqual(10); await waitFor(() => expect(stm.state.result?.totalRows).toEqual(10));
}); });
}); });
}); });