Files
Aniworld/tests/frontend/unit/setup.test.js
Lukas aceaba5849 feat: Set up JavaScript testing framework (Vitest + Playwright)
- Created package.json with Vitest and Playwright dependencies
- Configured vitest.config.js with happy-dom environment
- Configured playwright.config.js with Chromium browser
- Created test directory structure (tests/frontend/unit and e2e)
- Added setup.test.js with 10 Vitest validation tests
- Added setup.spec.js with 6 Playwright E2E validation tests
- Created FRONTEND_SETUP.md with Node.js installation guide
- Updated instructions.md marking task complete

Note: Requires Node.js installation before running tests
2026-02-01 09:37:55 +01:00

78 lines
2.1 KiB
JavaScript

/**
* Sample unit test to verify Vitest setup
* This test validates that the testing framework is working correctly
*/
import { beforeEach, describe, expect, it, vi } from 'vitest';
describe('Vitest Setup Validation', () => {
it('should run basic assertions', () => {
expect(true).toBe(true);
expect(1 + 1).toBe(2);
expect('hello').toContain('ello');
});
it('should support async tests', async () => {
const promise = Promise.resolve(42);
const result = await promise;
expect(result).toBe(42);
});
it('should support mocking', () => {
const mockFn = vi.fn().mockReturnValue('mocked');
const result = mockFn();
expect(mockFn).toHaveBeenCalled();
expect(result).toBe('mocked');
});
it('should have DOM environment available', () => {
// happy-dom provides DOM APIs
expect(typeof document).toBe('object');
expect(typeof window).toBe('object');
expect(typeof HTMLElement).toBe('function');
});
});
describe('DOM Manipulation Tests', () => {
beforeEach(() => {
// Reset document before each test
document.body.innerHTML = '';
});
it('should create and manipulate DOM elements', () => {
const div = document.createElement('div');
div.id = 'test-element';
div.textContent = 'Test Content';
document.body.appendChild(div);
const element = document.getElementById('test-element');
expect(element).not.toBeNull();
expect(element.textContent).toBe('Test Content');
});
it('should handle event listeners', () => {
const button = document.createElement('button');
const clickHandler = vi.fn();
button.addEventListener('click', clickHandler);
document.body.appendChild(button);
button.click();
expect(clickHandler).toHaveBeenCalledOnce();
});
it('should query elements with selectors', () => {
document.body.innerHTML = `
<div class="container">
<span class="item">Item 1</span>
<span class="item">Item 2</span>
<span class="item">Item 3</span>
</div>
`;
const items = document.querySelectorAll('.item');
expect(items.length).toBe(3);
expect(items[0].textContent).toBe('Item 1');
});
});