- Set up Vitest for unit testing with jsdom - Add test setup with Web Audio API and requestAnimationFrame mocks - Create initial test suites for DOM and animations modules - Add test scripts to package.json (test, test:ui, test:run, coverage) - Update CI workflow to include test execution - Create CONTRIBUTING.md with conventional commits guidelines - Create SECURITY.md with security policy - Update ESLint config to support test files - All tests passing (8/8) Co-authored-by: ZaneThePython <102631678+ZaneThePython@users.noreply.github.com>
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { typeWriter } from '../assets/js/modules/animations.js';
|
|
|
|
describe('Animations Module', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
});
|
|
|
|
describe('typeWriter', () => {
|
|
it('should type text character by character', async () => {
|
|
const element = document.createElement('div');
|
|
document.body.appendChild(element);
|
|
|
|
const text = 'Hello';
|
|
typeWriter(element, text, 50);
|
|
|
|
// Wait for first setTimeout to execute
|
|
await vi.runAllTimersAsync();
|
|
|
|
// Complete text should be shown
|
|
expect(element.innerHTML).toBe('Hello');
|
|
});
|
|
|
|
it('should handle null element gracefully', () => {
|
|
expect(() => {
|
|
typeWriter(null, 'text', 50);
|
|
}).not.toThrow();
|
|
});
|
|
|
|
it('should handle empty text', () => {
|
|
const element = document.createElement('div');
|
|
document.body.appendChild(element);
|
|
|
|
typeWriter(element, '', 50);
|
|
vi.advanceTimersByTime(100);
|
|
|
|
expect(element.innerHTML).toBe('');
|
|
});
|
|
});
|
|
});
|