-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
58 lines (44 loc) · 1.35 KB
/
index.test.js
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
import { h } from 'hastscript';
import { it, describe } from 'node:test';
import { equal, deepEqual } from 'node:assert/strict';
import { findParent } from './index.js';
describe('findParent', () => {
it('returns null when passed a falsey tree', () => {
const element = h('marquee');
equal(findParent(element), null);
});
it('returns null when passed a tree with no children', () => {
const element = h('marquee');
const tree = h('div', []);
equal(findParent(element, tree), null);
});
it('returns null when the element is not present in the tree', () => {
const element = h('marquee');
const tree = h('root', [
h('div.not-the-element'),
h('div.not-the-element-either')
]);
equal(findParent(element, tree), null);
});
it('returns the parent when the element is an immediate child of the root', () => {
const element = h('marquee');
const tree = h('root', [
h('div'),
element,
h('div')
]);
deepEqual(findParent(element, tree), tree);
});
it('returns the parent when the element is many branches away from the root', () => {
const leafEl = h('leaf');
const branchEl = h('branch', [leafEl]);
const tree = h('root', [
h('div'),
h('div', [
branchEl
]),
h('div')
]);
deepEqual(findParent(leafEl, tree), branchEl);
});
});