This repository was archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathtemplate-strip-visitor.spec.ts
More file actions
68 lines (61 loc) · 2.01 KB
/
template-strip-visitor.spec.ts
File metadata and controls
68 lines (61 loc) · 2.01 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
import {ASTNode} from '../ast';
import {cssNodeMatcherFactory} from '../node-matcher';
import {TemplateStripVisitor} from './';
describe('TemplateStripVisitor', () => {
let astRoot: ASTNode;
beforeEach(() => {
astRoot = {
nodeName: 'div',
attrs: [],
childNodes: []
};
const div1: ASTNode = { nodeName: 'div', attrs: [{ name: 'class', value: 'foo' }] };
const section: ASTNode = {
nodeName: 'section',
attrs: [],
parentNode: astRoot,
childNodes: [
div1
]
};
div1.parentNode = section;
const span1: ASTNode = { nodeName: 'span', childNodes: [], attrs: [], parentNode: astRoot };
const div2: ASTNode = {
nodeName: 'div',
parentNode: span1,
attrs: [{ name: 'class', value: 'foo' }]
};
span1.childNodes.push(div2);
const span2: ASTNode = { nodeName: 'span', attrs: [], parentNode: astRoot }
astRoot.childNodes.push(section);
astRoot.childNodes.push(span1);
astRoot.childNodes.push(span2);
});
it('should strip the root when match', (done: any) => {
let stripper = new TemplateStripVisitor(cssNodeMatcherFactory('div'));
stripper.visit(astRoot)
.then((astNode: ASTNode) => {
expect(astNode).toBe(null);
});
done();
});
it('should strip all nodes matching a selector', (done: any) => {
let stripper = new TemplateStripVisitor(cssNodeMatcherFactory('span'));
stripper.visit(astRoot)
.then((astNode: ASTNode) => {
expect(astNode.childNodes.length).toBe(1);
done();
});
});
it('should strip nodes in different areas of the tree', (done: any) => {
let stripper = new TemplateStripVisitor(cssNodeMatcherFactory('.foo'));
stripper.visit(astRoot)
.then((astNode: ASTNode) => {
// div > section > div.foo to be removed
expect(astNode.childNodes[0].childNodes.length).toBe(0);
// div > span > div.foo to be removed
expect(astNode.childNodes[1].childNodes.length).toBe(0);
done();
});
});
});