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 172
Expand file tree
/
Copy pathcss-selector.spec.ts
More file actions
53 lines (42 loc) · 1.61 KB
/
css-selector.spec.ts
File metadata and controls
53 lines (42 loc) · 1.61 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
import { CssSelector } from './css-selector';
describe('CssSelector', () => {
it('should support id selectors', () => {
const result = CssSelector.parse('#elemId');
expect(result.elementId).toBe('elemId');
});
it('should support element selectors', () => {
const result = CssSelector.parse('div');
expect(result.element).toBe('div');
});
it('should support class selectors', () => {
const result = CssSelector.parse('.foo');
expect(result.classNames).toBeTruthy();
expect(result.classNames.length).toBe(1);
expect(result.classNames[0]).toBe('foo');
});
describe('attribute selectors', () => {
it('should support attributes with no values', () => {
const result = CssSelector.parse('[title]');
expect(result.attrs['title']).toBe('');
});
it('should support attributes with values', () => {
const result = CssSelector.parse('[title=random title]');
expect(result.attrs['title']).toBe('random title');
});
});
describe('complex selectors', () => {
it('should support complex selectors', () => {
const result = CssSelector.parse('div.foo[attr]');
expect(result.element).toBe('div');
expect(result.classNames[0]).toBe('foo');
expect(result.attrs['attr']).toBe('');
});
it('should support complex selectors with terminals in random order', () => {
const result = CssSelector.parse('.foo[attr=bar].qux#baz');
expect(result.element).toBe(null);
expect(result.attrs['attr']).toBe('bar');
expect(result.elementId).toBe('baz');
expect(result.classNames).toEqual(['foo', 'qux']);
});
});
});