Files
gmtool/tests/core/escape-html.test.js
T

17 lines
617 B
JavaScript

import { describe, it, expect } from 'vitest';
import { escapeHtml } from '../../src/core/escape-html.js';
describe('escapeHtml', () => {
it('escapes the five HTML-significant characters', () => {
expect(escapeHtml(`a & b < c > d " e ' f`)).toBe('a &amp; b &lt; c &gt; d &quot; e &#39; f');
});
it('replaces & first so entities are not double-escaped', () => {
expect(escapeHtml('<')).toBe('&lt;');
expect(escapeHtml('&lt;')).toBe('&amp;lt;');
});
it('coerces null/undefined to empty string', () => {
expect(escapeHtml(null)).toBe('');
expect(escapeHtml(undefined)).toBe('');
});
});