-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathimage-alt-text-length.ts
More file actions
44 lines (42 loc) · 1.66 KB
/
image-alt-text-length.ts
File metadata and controls
44 lines (42 loc) · 1.66 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
import { describe, expect, test } from 'vitest'
import { runRule } from '../../lib/init-test'
import { incorrectAltTextLength } from '../../lib/linting-rules/image-alt-text-length'
import type { Rule } from '../../types'
describe(incorrectAltTextLength.names.join(' - '), () => {
test('image with incorrect alt text length fails', async () => {
const markdown = [
``,
``,
].join('\n')
const result = await runRule(incorrectAltTextLength as Rule, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(2)
expect(errors[0].lineNumber).toBe(1)
expect(errors[1].lineNumber).toBe(2)
expect(errors[0].errorRange).toEqual([3, 39])
expect(errors[1].errorRange).toEqual([3, 151])
})
test('image with correct length alt test passes', async () => {
const markdown = [
``,
``,
].join('\n')
const result = await runRule(incorrectAltTextLength as Rule, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(0)
})
test('image alt text that is entirely empty', async () => {
const markdown = [
'# Heading',
'',
// Completely empty
'',
].join('\n')
const result = await runRule(incorrectAltTextLength as Rule, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(1)
expect(errors[0].lineNumber).toBe(3)
// Because you can't get a valid range when it's entirely empty
expect(errors[0].errorRange).toEqual(null)
})
})