-
-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathhtml.spec.ts
More file actions
51 lines (42 loc) · 1.5 KB
/
html.spec.ts
File metadata and controls
51 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { describe, expect, it } from 'vitest'
import { decodeHtmlEntities, stripHtmlTags } from '../../../../shared/utils/html'
describe('decodeHtmlEntities', () => {
it.each([
['&', '&'],
['<', '<'],
['>', '>'],
['"', '"'],
[''', "'"],
[''', "'"],
[' ', '\u00A0'],
] as const)('%s → %s', (input, expected) => {
expect(decodeHtmlEntities(input)).toBe(expected)
})
it('decodes multiple entities in one string', () => {
expect(decodeHtmlEntities('a & b < c')).toBe('a & b < c')
})
it('leaves plain text unchanged', () => {
expect(decodeHtmlEntities('say no to bloat')).toBe('say no to bloat')
})
it('leaves unknown entities unchanged', () => {
expect(decodeHtmlEntities('&unknown;')).toBe('&unknown;')
})
})
describe('stripHtmlTags', () => {
it('removes simple HTML tags', () => {
expect(stripHtmlTags('<b>bold</b>')).toBe('bold')
})
it('removes anchor tags keeping text content', () => {
expect(stripHtmlTags('<a href="https://example.com">link</a>')).toBe('link')
})
it('removes self-closing tags', () => {
expect(stripHtmlTags('before<br/>after')).toBe('beforeafter')
})
it('leaves plain text unchanged', () => {
expect(stripHtmlTags('no tags here')).toBe('no tags here')
})
it('works with decodeHtmlEntities to clean descriptions', () => {
const raw = '<a href="url">link</a> and text'
expect(stripHtmlTags(decodeHtmlEntities(raw))).toBe('link and text')
})
})