Skip to content

Commit 16bfb6d

Browse files
Fix tests to work with Vitest
1 parent ca3d95d commit 16bfb6d

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

Diff for: src/components/timeline/__tests__/Timeline.test.tsx

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import { render, screen } from '@testing-library/react';
22
import '@testing-library/jest-dom';
3+
import { vi, describe, test, expect, beforeEach } from 'vitest';
34
import { Timeline } from '../Timeline';
45
import { TimelineEntry } from '../types';
56

67
// Mock the TimelineStep component
7-
jest.mock('../components/TimelineStep', () => {
8-
return {
9-
__esModule: true,
10-
default: ({ entry, index, isSelected, onSelect }: any) => (
11-
<div
12-
data-testid={`timeline-step-${index}`}
13-
data-selected={isSelected}
14-
onClick={() => onSelect(index)}
15-
>
16-
<span>{entry.type}</span>
17-
{entry.content && <span>{entry.content}</span>}
18-
{entry.command && <span>{entry.command}</span>}
19-
</div>
20-
)
21-
};
22-
});
8+
vi.mock('../components/TimelineStep', () => ({
9+
default: ({ entry, index, isSelected, onSelect }: any) => (
10+
<div
11+
data-testid={`timeline-step-${index}`}
12+
data-selected={isSelected.toString()}
13+
onClick={() => onSelect(index)}
14+
>
15+
<span>{entry.type}</span>
16+
{entry.content && <span>{entry.content}</span>}
17+
{entry.command && <span>{entry.command}</span>}
18+
</div>
19+
)
20+
}));
2321

2422
describe('Timeline Component', () => {
25-
const mockOnStepSelect = jest.fn();
26-
const mockOnCommandClick = jest.fn();
27-
const mockFormatTimelineDate = jest.fn().mockReturnValue('12:34 PM');
23+
const mockOnStepSelect = vi.fn();
24+
const mockOnCommandClick = vi.fn();
25+
const mockFormatTimelineDate = vi.fn().mockReturnValue('12:34 PM');
2826

2927
// Basic test to ensure the component renders
3028
test('renders without crashing', () => {

Diff for: src/components/timeline/__tests__/TimelineStep.test.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { render, screen } from '@testing-library/react';
22
import '@testing-library/jest-dom';
3+
import { vi, describe, test, expect } from 'vitest';
34
import TimelineStep from '../components/TimelineStep';
45
import { TimelineEntry } from '../types';
56

67
// Mock the formatTimelineDate function
7-
const mockFormatTimelineDate = jest.fn().mockReturnValue('12:34 PM');
8-
const mockOnSelect = jest.fn();
9-
const mockOnCommandClick = jest.fn();
8+
const mockFormatTimelineDate = vi.fn().mockReturnValue('12:34 PM');
9+
const mockOnSelect = vi.fn();
10+
const mockOnCommandClick = vi.fn();
1011

1112
describe('TimelineStep Component', () => {
1213
// Basic test to ensure the component renders
@@ -29,7 +30,7 @@ describe('TimelineStep Component', () => {
2930
/>
3031
);
3132

32-
expect(screen.getByText('Test content')).toBeInTheDocument();
33+
expect(screen.getAllByText('Test content').length).toBeGreaterThan(0);
3334
expect(screen.getByText('Assistant')).toBeInTheDocument();
3435
});
3536

Diff for: src/components/timeline/__tests__/types.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TimelineEntry } from '../types';
2+
import { describe, test, expect } from 'vitest';
23

34
describe('Timeline Types', () => {
45
test('TimelineEntry type supports screenshot in metadata', () => {

0 commit comments

Comments
 (0)