feat: add frontend unit tests with vitest (214 cases)

This commit is contained in:
a7m-1st 2025-08-25 04:45:35 +03:00
parent e7a5c5536f
commit 90864539e8
13 changed files with 3743 additions and 3 deletions

54
test/unit/basic.test.ts Normal file
View file

@ -0,0 +1,54 @@
// Simple example test to verify testing setup
import { describe, it, expect } from 'vitest'
describe('Basic Testing Setup', () => {
it('should be able to run basic tests', () => {
expect(1 + 1).toBe(2)
})
it('should handle string operations', () => {
const greeting = 'Hello, World!'
expect(greeting).toContain('World')
expect(greeting.length).toBe(13)
})
it('should handle array operations', () => {
const numbers = [1, 2, 3, 4, 5]
expect(numbers).toHaveLength(5)
expect(numbers).toContain(3)
expect(numbers.reduce((a, b) => a + b, 0)).toBe(15)
})
it('should handle async operations', async () => {
const asyncFunction = () => Promise.resolve('async result')
const result = await asyncFunction()
expect(result).toBe('async result')
})
it('should handle mock functions', () => {
const mockFn = vi.fn()
mockFn('test argument')
expect(mockFn).toHaveBeenCalledOnce()
expect(mockFn).toHaveBeenCalledWith('test argument')
})
})
// Mock example
import { vi } from 'vitest'
const mockMathOperations = {
add: (a: number, b: number) => a + b,
multiply: (a: number, b: number) => a * b
}
describe('Mock Example', () => {
it('should mock functions correctly', () => {
const mockAdd = vi.spyOn(mockMathOperations, 'add')
mockAdd.mockReturnValue(10)
const result = mockMathOperations.add(2, 3)
expect(result).toBe(10) // Returns mocked value, not actual sum
expect(mockAdd).toHaveBeenCalledWith(2, 3)
})
})