-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
117 lines (107 loc) · 2.72 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import assert from 'node:assert/strict'
import test from 'node:test'
import {parseSelector} from 'hast-util-parse-selector'
test('parseSelector()', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(
Object.keys(await import('hast-util-parse-selector')).sort(),
['parseSelector']
)
})
await t.test(
'should return an empty element without selector',
async function () {
assert.deepEqual(parseSelector(), {
type: 'element',
tagName: 'div',
properties: {},
children: []
})
}
)
await t.test(
'should return an element with a tag-name when given a tag-name',
async function () {
assert.deepEqual(parseSelector('foo'), {
type: 'element',
tagName: 'foo',
properties: {},
children: []
})
}
)
await t.test(
'should return an `defaultTagName` if no tag name is defined in `selector` (#1)',
async function () {
assert.deepEqual(parseSelector(undefined, 'g'), {
type: 'element',
tagName: 'g',
properties: {},
children: []
})
}
)
await t.test(
'should return an `defaultTagName` if no tag name is defined in `selector` (#2)',
async function () {
assert.deepEqual(parseSelector('#id', 'g'), {
type: 'element',
tagName: 'g',
properties: {id: 'id'},
children: []
})
}
)
await t.test(
'should return a `div` element when given a class',
async function () {
assert.deepEqual(parseSelector('.bar'), {
type: 'element',
tagName: 'div',
properties: {className: ['bar']},
children: []
})
}
)
await t.test(
'should return a `div` element when given an ID',
async function () {
assert.deepEqual(parseSelector('#bar'), {
type: 'element',
tagName: 'div',
properties: {id: 'bar'},
children: []
})
}
)
await t.test('should return attributes', async function () {
assert.deepEqual(parseSelector('foo#bar.baz.qux'), {
type: 'element',
tagName: 'foo',
properties: {
id: 'bar',
className: ['baz', 'qux']
},
children: []
})
})
await t.test(
'should return the last ID if multiple are found',
async function () {
assert.deepEqual(parseSelector('foo#bar#baz'), {
type: 'element',
tagName: 'foo',
properties: {id: 'baz'},
children: []
})
}
)
await t.test('should *not* case the tag-name', async function () {
assert.deepEqual(parseSelector('Foo'), {
type: 'element',
tagName: 'Foo',
properties: {},
children: []
})
})
})