Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fake timers in test to fix potential issue with window references post test #1197

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading