-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathbetterLinkDocumentMod.ariaLabel.spec.ts
More file actions
51 lines (40 loc) · 1.96 KB
/
betterLinkDocumentMod.ariaLabel.spec.ts
File metadata and controls
51 lines (40 loc) · 1.96 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
/** @jest-environment @happy-dom/jest-environment */
/// <reference types="jest" />
import { micromark } from 'micromark';
import betterLinkDocumentMod, { type BetterLinkDocumentModDecoration } from './betterLinkDocumentMod';
import parseDocumentFragmentFromString from './parseDocumentFragmentFromString';
import serializeDocumentFragmentIntoString from './serializeDocumentFragmentIntoString';
const BASE_MARKDOWN = '[Example](https://example.com)';
let baseHTML: string;
beforeEach(() => {
baseHTML = micromark(BASE_MARKDOWN, { allowDangerousHtml: true });
});
describe('When passing "ariaLabel" option with "Hello, World!"', () => {
let actual: DocumentFragment;
const decoration: BetterLinkDocumentModDecoration = { ariaLabel: 'Hello, World!' };
beforeEach(() => {
actual = betterLinkDocumentMod(parseDocumentFragmentFromString(baseHTML), () => decoration);
});
test('should have "aria-label" attribute set to "Hello, World!"', () =>
expect(actual.querySelector('a')?.getAttribute('aria-label')).toBe('Hello, World!'));
test('should match snapshot', () =>
expect(serializeDocumentFragmentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" aria-label="Hello, World!">Example</a></p>'
));
});
describe('When passing "ariaLabel" option with false', () => {
let actual: DocumentFragment;
const decoration: BetterLinkDocumentModDecoration = { ariaLabel: false };
beforeEach(() => {
actual = betterLinkDocumentMod(
parseDocumentFragmentFromString('<a href="https://example.com" aria-label="Hello, World!">Example</a>'),
() => decoration
);
});
test('should have "aria-label" attribute removed', () =>
expect(actual.querySelector('a')?.hasAttribute('aria-label')).toBe(false));
test('should match snapshot', () =>
expect(serializeDocumentFragmentIntoString(actual)).toBe(
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>'
));
});