Repository navigation
Expand file tree
/
Copy pathis-node-in-scan-context.test.ts
More file actions
70 lines (52 loc) · 2.43 KB
/
Copy pathis-node-in-scan-context.test.ts
File metadata and controls
70 lines (52 loc) · 2.43 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
66
67
68
69
70
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { JSDOM } from 'jsdom';
import { isNodeInScanContext } from './is-node-in-scan-context';
suite('isNodeInScanContext', () => {
test('doesn’t include an element if scan context is empty', () => {
const dom = new JSDOM('<div id="test"></div>');
const { document } = dom.window;
const node = document.querySelector('#test')!;
const scanContext = { include: [], exclude: [] };
assert.equal(isNodeInScanContext(node, scanContext), false);
});
test('includes an element whose ancestor is included', () => {
const dom = new JSDOM('<div id="test"></div>');
const { document } = dom.window;
const node = document.querySelector('#test')!;
const body = document.body;
const scanContext = { include: [body], exclude: [] };
assert.ok(isNodeInScanContext(node, scanContext));
});
test('does not include an element whose closest ancestor is excluded', () => {
const dom = new JSDOM('<div id="excluded"><div id="test"></div></div>');
const { document } = dom.window;
const node = document.querySelector('#test')!;
const body = document.body;
const excludedAncestor = document.querySelector('#excluded')!;
const scanContext = { include: [body], exclude: [excludedAncestor] };
assert.equal(isNodeInScanContext(node, scanContext), false);
});
test('includes an element if it itself is included', () => {
const dom = new JSDOM('<div id="test"></div>');
const { document } = dom.window;
const node = document.querySelector('#test')!;
const scanContext = { include: [node], exclude: [] };
assert.ok(isNodeInScanContext(node, scanContext));
});
test('doesn’t include an element if it itself is excluded', () => {
const dom = new JSDOM('<div id="test"></div>');
const { document } = dom.window;
const node = document.querySelector('#test')!;
const body = document.body;
const scanContext = { include: [body], exclude: [node] };
assert.equal(isNodeInScanContext(node, scanContext), false);
});
test('includes an element if it’s both included and excluded (include takes precedence)', () => {
const dom = new JSDOM('<div id="test"></div>');
const { document } = dom.window;
const node = document.querySelector('#test')!;
const scanContext = { include: [node], exclude: [node] };
assert.ok(isNodeInScanContext(node, scanContext));
});
});