Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
prayanshchh committed Nov 23, 2024
1 parent 565c161 commit 3d8cb16
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/vitest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@ import '@testing-library/jest-dom';

describe('Vitest Configuration', () => {
it('should support TypeScript', () => {
const value = 42;
expect(typeof value).toBe('number');
interface TestInterface {
id: number;
name: string;
}
const value: TestInterface = { id: 42, name: 'test' };
expect(value.id).toBe(42);
expect(value.name).toBe('test');
});

it('should support DOM testing', async () => {
it('should support DOM testing', () => {
render(<div data-testid="test">Hello</div>);
expect(screen.getByTestId('test')).toBeInTheDocument();
});

it('should support mocking', async () => {
it('should support mocking', () => {
const mock = vi.fn().mockReturnValue('mocked');
expect(mock()).toBe('mocked');

// Test spy functionality
const spy = vi.spyOn(console, 'log');
console.log('test');

expect(spy).toHaveBeenCalledWith('test');

// Test mock implementation
const mockWithImpl = vi.fn().mockImplementation((x: number) => x * 2);
expect(mockWithImpl(2)).toBe(4);
});
});

0 comments on commit 3d8cb16

Please sign in to comment.