Skip to content

Commit

Permalink
Added test for issue 14 ( using an HTMLCollection as parameter to fin…
Browse files Browse the repository at this point in the history
…d() ) and patched.
  • Loading branch information
Fil Maj committed Jan 18, 2011
1 parent efb507a commit e0b9a26
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions spec/index-bb.html
Expand Up @@ -58,6 +58,10 @@ <h2 id="qunit-userAgent"></h2>
<li class="item" id="item_2">this is item two</li>
<li class="item" id="item_3">this is item three</li>
</ul>
<form id="form_1">
<input type="text" id="text_input_1" value="test" />
<input type="checkbox" id="checkbox_input_1" value="test" />
</form>
</div>

<div id="style_tests">
Expand Down
4 changes: 4 additions & 0 deletions spec/index-ie.html
Expand Up @@ -58,6 +58,10 @@ <h2 id="qunit-userAgent"></h2>
<li class="item" id="item_2">this is item two</li>
<li class="item" id="item_3">this is item three</li>
</ul>
<form id="form_1">
<input type="text" id="text_input_1" value="test" />
<input type="checkbox" id="checkbox_input_1" value="test" />
</form>
</div>

<div id="style_tests">
Expand Down
4 changes: 4 additions & 0 deletions spec/index.html
Expand Up @@ -58,6 +58,10 @@ <h2 id="qunit-userAgent"></h2>
<li class="item" id="item_2">this is item two</li>
<li class="item" id="item_3">this is item three</li>
</ul>
<form id="form_1">
<input type="text" id="text_input_1" value="test" />
<input type="checkbox" id="checkbox_input_1" value="test" />
</form>
</div>

<div id="style_tests">
Expand Down
18 changes: 13 additions & 5 deletions spec/tests/core-tests.js
Expand Up @@ -13,41 +13,49 @@ CoreTests.prototype.run = function () {
}
});
test( '.find()', function(){
expect(1);
x = x$('#find_tests_inner').find('.foo');
equals(x[0].innerHTML, 'second', 'Should set context properly and limit tree searches to base xui object');
});
test( '.has()', function(){
expect(1);
equals(x.has(".foo").length, 2, 'Should return number of elements after including a specific class as defined in markup');
});
test( '.not()', function(){
expect(1);
equals(x.not(".foo").length, 3, 'Should return number of elements after omitting a specific class as defined in markup');
});

module("Selectors (base.js)", {
module("Base (base.js)", {
setup:function() {},
teardown:function() {
x = null;
}
});
test( 'ID selector', function(){
expect(3);
x = x$('#item_1');
equals(x.length, 1, 'Should return non-zero length array for existing elements with specified ID');
equals(x[0].innerHTML, 'this is item one', 'Should contain innerHTML as exists in markup');
x = x$('#idontthinkthisitemexists');
equals(x.length, 0, 'Should return a zero length array for non-existing elements');
});
test('Class selector', function() {
expect(3);
x = x$(".item");
equals(x.length, 3, 'Should return number of elements with class the proper specified class');
equals(x[0].innerHTML, 'this is item one', 'Should have text as specified in markup');
equals(x[x.length -1].innerHTML, 'this is item three', 'Should have text as specified in markup');
equals(x[x.length - 1].innerHTML, 'this is item three', 'Should have text as specified in markup');
});
test('Element reference selector', function() {
el = document.getElementById("item_1"),
test('Element(s) reference selector', function() {
expect(3);
var el = document.getElementById("item_1"),
x = x$(el);
equals(x.length, 1, 'Should return array with one element');
equals(x[0].innerHTML, 'this is item one', 'Should have proper text as defined in page markup');
el = null;
var formEls = document.getElementById('form_1').elements;
x = x$(formEls);
equals(x.length, 2, 'Should return proper number of elements when passing in a HTMLCollection object')
});
test('Tag name selector', function() {
expect(2);
Expand Down
2 changes: 1 addition & 1 deletion src/base.js
Expand Up @@ -156,7 +156,7 @@ xui.fn = xui.prototype = {
ele = slice(ele);
} else if (q instanceof Array) {
ele = q;
} else if (q.toString() == '[object NodeList]') {
} else if (q.toString() == '[object NodeList]' || q.toString() == '[object HTMLCollection]') {
ele = slice(q);
} else if (q.nodeName || q === window) { // only allows nodes in
// an element was passed in
Expand Down

0 comments on commit e0b9a26

Please sign in to comment.