Merge pull request #6 from Na7coldwater/unit_tests

Two unit tests and fix for issue #5
This commit is contained in:
Timothy Warren 2011-07-14 03:34:49 -07:00
commit afde37c6e3
3 changed files with 50 additions and 6 deletions

11
kis.js
View File

@ -64,20 +64,23 @@
*/ */
$_ = function(sel) $_ = function(sel)
{ {
// Make a copy before adding properties
var self = dcopy($_);
//Get the DOM objects from the selector //Get the DOM objects from the selector
sel = $(sel); sel = $(sel);
//Have window be default selector, just in case //Have window be default selector, just in case
if(typeof sel === "undefined") if(typeof sel === "undefined")
{ {
sel = (typeof $_.el !== "undefined") sel = (typeof self.el !== "undefined")
? $_.el ? self.el
: window; : window;
} }
$_.el = sel; self.el = sel;
return dcopy($_); return self;
}; };
/** /**

View File

@ -11,7 +11,10 @@
<div id="qunit-testrunner-toolbar"></div> <div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2> <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol> <ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div> <div id="qunit-fixture">
test markup, will be hidden
<span id="testSpan"></span>
</div>
<section> <section>
<article id="r14"></article> <article id="r14"></article>
<aside></aside> <aside></aside>

View File

@ -33,4 +33,42 @@
module("ajax"); module("ajax");
// --------------------------------------------------------------------------
module("events");
test("Browser expando support", function() {
expect(3);
// kis-js events uses expando properties to store event listeners
// If this test fails, the event module will likely fail as well
var ele = document.createElement("div");
ele.expando = {a:5, b:"c", c: function cool(){return ele}};
equals(ele.expando.a, 5);
equals(ele.expando.b, "c");
equals(ele.expando.c(), ele,
"Closure isn't broken by being assigned to an expando property");
});
// --------------------------------------------------------------------------
module("dom");
test("Add/Remove Class", function() {
expect(4);
var $test = $_("#testSpan");
var ele = $test.el;
$test.dom.addClass("coolClass");
equals(ele.className, "coolClass");
$test.dom.addClass("anotherClass");
equals(ele.className, "coolClass anotherClass");
$test.dom.removeClass("coolClass");
equals(ele.className, "anotherClass");
$test.dom.removeClass("anotherClass");
ok(ele.className === undefined || ele.className === "", "testSpan.className is empty");
});
}()); }());