mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-29 04:00:09 +00:00
feat: add frontend unit tests with vitest (214 cases)
This commit is contained in:
parent
e7a5c5536f
commit
90864539e8
13 changed files with 3743 additions and 3 deletions
54
test/unit/basic.test.ts
Normal file
54
test/unit/basic.test.ts
Normal 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)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue