Skip to content

Commit 90b7d1a

Browse files
author
taoqiufeng
committed
test: queryselector by property
1 parent 2504afe commit 90b7d1a

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

test/html.js

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ describe('HTML Parser', function () {
1111
var TextNode = HTMLParser.TextNode;
1212

1313
describe('Matcher', function () {
14-
1514
it('should match corrent elements', function () {
16-
1715
var matcher = new Matcher('#id .a a.b *.a.b .a.b * a');
1816
var MatchesNothingButStarEl = new HTMLElement('_', {});
1917
var withIdEl = new HTMLElement('p', { id: 'id' });
@@ -55,15 +53,12 @@ describe('HTML Parser', function () {
5553
matcher.advance(withClassNameEl).should.be.ok; // a
5654

5755
matcher.matched.should.be.ok;
58-
5956
});
60-
6157
});
6258

6359
var parseHTML = HTMLParser.parse;
6460

6561
describe('parse()', function () {
66-
6762
it('should parse "<p id=\\"id\\"><a class=\'cls\'>Hello</a><ul><li><li></ul><span></span></p>" and return root element', function () {
6863

6964
var root = parseHTML('<p id="id"><a class=\'cls\'>Hello</a><ul><li><li></ul><span></span></p>');
@@ -77,7 +72,6 @@ describe('HTML Parser', function () {
7772
p.appendChild(new HTMLElement('span', {}, ''));
7873

7974
root.firstChild.should.eql(p);
80-
8175
});
8276

8377
it('should parse "<DIV><a><img/></A><p></P></div>" and return root element', function () {
@@ -160,7 +154,6 @@ describe('HTML Parser', function () {
160154
});
161155

162156
describe('TextNode', function () {
163-
164157
describe('#isWhitespace', function () {
165158
var node = new TextNode('');
166159
node.isWhitespace.should.be.ok;
@@ -169,105 +162,77 @@ describe('HTML Parser', function () {
169162
node = new TextNode(' \t&nbsp; \t');
170163
node.isWhitespace.should.be.ok;
171164
});
172-
173165
});
174166

175167
describe('HTMLElement', function () {
176168

177169
describe('#removeWhitespace()', function () {
178-
179170
it('should remove whitespaces while preserving nodes with content', function () {
180-
181171
var root = parseHTML('<p> \r \n \t <h5> 123 </h5></p>');
182172

183173
var p = new HTMLElement('p', {}, '');
184174
p.appendChild(new HTMLElement('h5', {}, ''))
185175
.appendChild(new TextNode('123'));
186176

187177
root.firstChild.removeWhitespace().should.eql(p);
188-
189178
});
190-
191179
});
192180

193181
describe('#rawAttributes', function () {
194-
195182
it('should return escaped attributes of the element', function () {
196-
197183
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\'></p>');
198-
199184
root.firstChild.rawAttributes.should.eql({
200185
'a': '12',
201186
'data-id': '!$$&amp;',
202187
'yAz': '1'
203188
});
204-
205189
});
206-
207190
});
208191

209192
describe('#attributes', function () {
210-
211193
it('should return attributes of the element', function () {
212-
213194
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\'></p>');
214-
215195
root.firstChild.attributes.should.eql({
216196
'a': '12',
217197
'data-id': '!$$&',
218198
'yAz': '1'
219199
});
220-
221200
});
222-
223201
});
224202

225203
describe('#querySelector()', function () {
226-
227204
it('should return correct elements in DOM tree', function () {
228-
229-
var root = parseHTML('<a id="id"><div><span class="a b"></span><span></span><span></span></div></a>');
230-
205+
var root = parseHTML('<a id="id" data-id="myid"><div><span class="a b"></span><span></span><span></span></div></a>');
231206
root.querySelector('#id').should.eql(root.firstChild);
232207
root.querySelector('span.a').should.eql(root.firstChild.firstChild.firstChild);
233208
root.querySelector('span.b').should.eql(root.firstChild.firstChild.firstChild);
234209
root.querySelector('span.a.b').should.eql(root.firstChild.firstChild.firstChild);
235210
root.querySelector('#id .b').should.eql(root.firstChild.firstChild.firstChild);
236211
root.querySelector('#id span').should.eql(root.firstChild.firstChild.firstChild);
237-
212+
root.querySelector('[data-id=myid]').should.eql(root.firstChild);
213+
root.querySelector('[data-id="myid"]').should.eql(root.firstChild);
238214
});
239-
240215
});
241216

242217
describe('#querySelectorAll()', function () {
243-
244218
it('should return correct elements in DOM tree', function () {
245-
246219
var root = parseHTML('<a id="id"><div><span class="a b"></span><span></span><span></span></div></a>');
247-
248220
root.querySelectorAll('#id').should.eql([root.firstChild]);
249221
root.querySelectorAll('span.a').should.eql([root.firstChild.firstChild.firstChild]);
250222
root.querySelectorAll('span.b').should.eql([root.firstChild.firstChild.firstChild]);
251223
root.querySelectorAll('span.a.b').should.eql([root.firstChild.firstChild.firstChild]);
252224
root.querySelectorAll('#id .b').should.eql([root.firstChild.firstChild.firstChild]);
253225
root.querySelectorAll('#id span').should.eql(root.firstChild.firstChild.childNodes);
254-
255226
});
256-
257227
});
258228

259229
describe('#structuredText', function () {
260-
261230
it('should return correct structured text', function () {
262-
263231
var root = parseHTML('<span>o<p>a</p><p>b</p>c</span>');
264232
root.structuredText.should.eql('o\na\nb\nc');
265-
266233
});
267-
268234
});
269235
describe('#set_content', function () {
270-
271236
it('set content string', function () {
272237
var root = parseHTML('<div></div>');
273238
root.childNodes[0].set_content('<span><div>abc</div>bla</span>');
@@ -288,9 +253,7 @@ describe('HTML Parser', function () {
288253
root.childNodes[0].set_content('abc');
289254
root.toString().should.eql('<div>abc</div>');
290255
});
291-
292256
});
293-
294257
});
295258

296259
describe('stringify', function () {

0 commit comments

Comments
 (0)