forked from mgechev/codelyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreferenceCollectorVisitor.spec.ts
More file actions
47 lines (42 loc) · 1.92 KB
/
referenceCollectorVisitor.spec.ts
File metadata and controls
47 lines (42 loc) · 1.92 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
import { parseTemplate } from '../../src/angular/templates/templateParser';
import { ReferenceCollectorVisitor } from '../../src/angular/templates/referenceCollectorVisitor';
import { templateVisitAll } from '@angular/compiler';
import { expect } from 'chai';
describe('ReferenceCollectorVisitor', () => {
it('should work with empty templates', () => {
const template = parseTemplate('');
const rv = new ReferenceCollectorVisitor();
templateVisitAll(rv, template, null);
expect(Object.keys(rv.variables).length).eq(0);
});
it('should work with simple templates', () => {
const template = parseTemplate('<div></div>');
const rv = new ReferenceCollectorVisitor();
templateVisitAll(rv, template, null);
expect(Object.keys(rv.variables).length).eq(0);
});
it('should work with templates with one reference', () => {
const template = parseTemplate('<div #foo></div>');
const rv = new ReferenceCollectorVisitor();
templateVisitAll(rv, template, null);
expect(Object.keys(rv.variables).length).eq(1);
expect(rv.variables['foo']).to.eq(true);
});
it('should work with templates with nested elements with references', () => {
const template = parseTemplate('<div #foo><span #bar></span></div>');
const rv = new ReferenceCollectorVisitor();
templateVisitAll(rv, template, null);
expect(Object.keys(rv.variables).length).eq(2);
expect(rv.variables['bar']).to.eq(true);
expect(rv.variables['foo']).to.eq(true);
});
it('should work with templates with multiple elements with different references', () => {
const template = parseTemplate('<div #foo><span #bar></span></div><span #qux></span>');
const rv = new ReferenceCollectorVisitor();
templateVisitAll(rv, template, null);
expect(Object.keys(rv.variables).length).eq(3);
expect(rv.variables['foo']).eq(true);
expect(rv.variables['bar']).eq(true);
expect(rv.variables['qux']).eq(true);
});
});