From 3d8cb16b5ca6bff9e63691783c0531ac22741df7 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 24 Nov 2024 00:46:07 +0530 Subject: [PATCH] suggestion #2 --- src/vitest.test.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/vitest.test.tsx b/src/vitest.test.tsx index eeed44dfd6..297b1f28f0 100644 --- a/src/vitest.test.tsx +++ b/src/vitest.test.tsx @@ -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(
Hello
); 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); }); });