-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathocticon.ts
More file actions
45 lines (38 loc) · 1.74 KB
/
octicon.ts
File metadata and controls
45 lines (38 loc) · 1.74 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
import { describe, expect, test } from 'vitest'
import { renderContent } from '@/content-render/index'
describe('octicon tag', () => {
test('renders the expected octicon', async () => {
const actual = await renderContent('{% octicon "check" %}')
expect(actual).toContain('<svg ')
expect(actual).toContain('class="octicon octicon-check"')
})
test('renders the expected octicon with an option', async () => {
const actual = await renderContent('{% octicon "check" width="64" %}')
expect(actual).toContain('<svg ')
expect(actual).toContain('class="octicon octicon-check"')
expect(actual).toContain('width="64"')
})
test('renders the expected octicon with multiple options', async () => {
const actual = await renderContent('{% octicon "check" width="64" aria-label="A checkmark" %}')
expect(actual).toContain('<svg ')
expect(actual).toContain('class="octicon octicon-check"')
expect(actual).toContain('width="64"')
expect(actual).toContain('aria-label="A checkmark"')
})
test('uses label to set aria-label', async () => {
const actual = await renderContent('{% octicon "check" label="A checkmark" %}')
expect(actual).toContain('<svg ')
expect(actual).toContain('class="octicon octicon-check"')
expect(actual).toContain('aria-label="A checkmark"')
})
test('throws an error with invalid syntax', async () => {
await expect(renderContent('{% octicon 123 %}')).rejects.toThrowError(
'Syntax Error in tag \'octicon\' - Valid syntax: octicon "<name>" <key="value">',
)
})
test('throws an error with a non-existant octicon', async () => {
await expect(renderContent('{% octicon "pizza-patrol" %}')).rejects.toThrowError(
'Octicon pizza-patrol does not exist',
)
})
})