feat: Add testing infrastructure and documentation
- 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>
This commit is contained in:
40
tests/animations.test.js
Normal file
40
tests/animations.test.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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('');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user