Skip to content

Commit

Permalink
Use fake timers in test to fix potential issue with window referenc…
Browse files Browse the repository at this point in the history
…es post test (#1197)
  • Loading branch information
duranb authored Mar 29, 2024
1 parent 0392524 commit 0be6b90
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/ui/DataGrid/DataGrid.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cleanup, fireEvent, render } from '@testing-library/svelte';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
import DataGrid from './DataGrid.svelte';

const numOfRows = 10;
Expand All @@ -15,6 +15,15 @@ vi.stubGlobal(
);

describe('DataGrid Component', () => {
beforeAll(() => {
vi.useFakeTimers();
});

afterAll(() => {
vi.runOnlyPendingTimers();
vi.useRealTimers();
});

afterEach(() => {
cleanup();
});
Expand Down Expand Up @@ -94,8 +103,7 @@ describe('DataGrid Component', () => {

expect(container.querySelectorAll('.ag-center-cols-container .ag-row.ag-row-selected')).toHaveLength(3);

// need to wait for the component to fully update
await new Promise(resolve => setTimeout(resolve, 0));
await vi.runOnlyPendingTimers();

expect(
container.querySelector('.ag-center-cols-container .ag-row.ag-row-selected.ag-current-row-selected'),
Expand Down

0 comments on commit 0be6b90

Please sign in to comment.