Files
cinny/src/app/utils/htmlEntities.test.ts
T

29 lines
1.1 KiB
TypeScript
Raw Normal View History

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { decodeHtmlEntities } from './htmlEntities';
test('decodes the leftover entity from a double-encoded meta tag (Steam)', () => {
assert.equal(
decodeHtmlEntities('The "Perpetual Testing Initiative" has been expanded'),
'The "Perpetual Testing Initiative" has been expanded',
);
});
test('named, decimal and hex references', () => {
assert.equal(
decodeHtmlEntities('Tom & Jerry 'n' co — …'),
"Tom & Jerry 'n' co — …",
);
assert.equal(decodeHtmlEntities('emoji 😀'), 'emoji 😀');
});
test('leaves plain text, unknown names and bare ampersands alone', () => {
assert.equal(decodeHtmlEntities('no entities here'), 'no entities here');
assert.equal(decodeHtmlEntities('AT&T and &bogus; stay'), 'AT&T and &bogus; stay');
assert.equal(decodeHtmlEntities('� �'), '� �');
});
test('decodes only one level (a literal &amp;lt; becomes &lt;, not <)', () => {
assert.equal(decodeHtmlEntities('&amp;lt;b&amp;gt;'), '&lt;b&gt;');
});