-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathhelpers.spec.ts
More file actions
65 lines (53 loc) · 1.97 KB
/
helpers.spec.ts
File metadata and controls
65 lines (53 loc) · 1.97 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { deepMerge, inheritAriaAttributes } from './helpers';
describe('inheritAriaAttributes', () => {
it('should inherit aria attributes', () => {
const parent = document.createElement('div');
parent.setAttribute('aria-label', 'parent');
parent.setAttribute('aria-hidden', 'true');
parent.setAttribute('role', 'button');
const inheritedAriaAttributes = inheritAriaAttributes(parent);
expect(inheritedAriaAttributes).toEqual({
'aria-label': 'parent',
'aria-hidden': 'true',
role: 'button',
});
});
it('should not inherit non-aria attributes', () => {
const parent = document.createElement('button');
parent.setAttribute('type', 'submit');
const inheritedAriaAttributes = inheritAriaAttributes(parent);
expect(inheritedAriaAttributes).toEqual({});
});
it('attributes that are ignored should not be returned', () => {
const parent = document.createElement('div');
parent.setAttribute('aria-label', 'parent');
parent.setAttribute('aria-hidden', 'true');
parent.setAttribute('role', 'button');
const ignoreList = ['aria-hidden'];
const inheritedAriaAttributes = inheritAriaAttributes(parent, ignoreList);
expect(inheritedAriaAttributes).toEqual({
'aria-label': 'parent',
role: 'button',
});
});
});
describe('deepMerge', () => {
it('should merge objects', () => {
const target = { a: 1, b: 2 };
const source = { b: 3, c: 4 };
const result = deepMerge(target, source);
expect(result).toEqual({ a: 1, b: 3, c: 4 });
});
it('should merge objects when target is undefined', () => {
const target = undefined;
const source = { a: 1, b: 2 };
const result = deepMerge(target, source);
expect(result).toEqual({ a: 1, b: 2 });
});
it('should merge objects when source is undefined', () => {
const target = { a: 1, b: 2 };
const source = undefined;
const result = deepMerge(target, source);
expect(result).toEqual({ a: 1, b: 2 });
});
});