Files
landing/tests/unit/copyright-year.test.ts
mifi dfa18c8560
Some checks failed
ci/woodpecker/push/ci Pipeline failed
ci/woodpecker/push/deploy unknown status
A bit of JS to improve the UX slightly... More tests. Everything is kosher now.
2026-02-01 19:01:12 -03:00

45 lines
1.2 KiB
TypeScript

/**
* @vitest-environment jsdom
*/
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
const __dirname = dirname(fileURLToPath(import.meta.url));
const SCRIPT_PATH = join(__dirname, '../../static/assets/js/copyright-year.js');
describe('copyright-year.js', () => {
let el: HTMLSpanElement;
beforeEach(() => {
el = document.createElement('span');
el.id = 'copyright-year';
el.textContent = 'placeholder';
document.body.appendChild(el);
});
afterEach(() => {
el.remove();
});
it('sets #copyright-year textContent to current year when element exists', () => {
const code = readFileSync(SCRIPT_PATH, 'utf8');
eval(code);
const expected = new Date().getFullYear().toString();
expect(el.textContent).toBe(expected);
});
it('does not throw when #copyright-year is missing', () => {
el.remove();
const code = readFileSync(SCRIPT_PATH, 'utf8');
expect(() => {
eval(code);
}).not.toThrow();
});
});