generated from coulomb/repo-seed
test: improve test infrastructure and fix test assertions
- Add mockPapaParse helper to centralize CSV mocking - Fix test assertions to match actual output (German month names) - Add missing DOM elements to test setup (projectFile, csvFile, etc.) - Update vitest to v4.0.14 for improved testing capabilities - Make setupEventHandlers globally accessible for testing - Use textContent instead of innerText for better consistency - Fix autoLoadDefaultProject test to check all three fallback paths - Add proper event handler setup in integration tests - Improve error handling test assertions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -52,11 +52,30 @@ export const createSampleTemplate = () => `<svg xmlns="http://www.w3.org/2000/sv
|
||||
export const mockFetch = (data, ok = true) => {
|
||||
global.fetch.mockResolvedValueOnce({
|
||||
ok,
|
||||
status: ok ? 200 : 404,
|
||||
statusText: ok ? 'OK' : 'Not Found',
|
||||
json: () => Promise.resolve(data),
|
||||
text: () => Promise.resolve(typeof data === 'string' ? data : JSON.stringify(data))
|
||||
})
|
||||
}
|
||||
|
||||
// Helper to mock Papa.parse with proper CSV parsing
|
||||
export const mockPapaParse = () => {
|
||||
global.Papa.parse.mockImplementation((text, options) => {
|
||||
const lines = text.trim().split('\n')
|
||||
const headers = lines[0].split(',')
|
||||
const data = lines.slice(1).map(line => {
|
||||
const values = line.split(',')
|
||||
const obj = {}
|
||||
headers.forEach((header, i) => {
|
||||
obj[header] = values[i]
|
||||
})
|
||||
return obj
|
||||
})
|
||||
options.complete({ data })
|
||||
})
|
||||
}
|
||||
|
||||
export const expectElementToHaveText = (selector, text) => {
|
||||
const element = document.querySelector(selector)
|
||||
expect(element).toBeTruthy()
|
||||
|
||||
Reference in New Issue
Block a user