From 4c1bfea9e921efda691d92bef3b3fe8a4c695cbc Mon Sep 17 00:00:00 2001 From: Nate B <0nathan0nathan0nathan0+github@gmail.com> Date: Wed, 13 Jul 2011 22:36:52 -0600 Subject: [PATCH 1/2] Added two unit tests --- tests/index.html | 5 ++++- tests/tests.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/index.html b/tests/index.html index 479a687..a522980 100644 --- a/tests/index.html +++ b/tests/index.html @@ -11,7 +11,10 @@

    -
    test markup, will be hidden
    +
    + test markup, will be hidden + +
    diff --git a/tests/tests.js b/tests/tests.js index 5b70da1..59458eb 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -33,4 +33,42 @@ 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"); + }); }()); \ No newline at end of file From f7bf984d681c6e1667d53be4f0112103162279f8 Mon Sep 17 00:00:00 2001 From: Nate B <0nathan0nathan0nathan0+github@gmail.com> Date: Wed, 13 Jul 2011 22:41:34 -0600 Subject: [PATCH 2/2] Fix issue #5 --- kis.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kis.js b/kis.js index e7c1489..b6d4666 100644 --- a/kis.js +++ b/kis.js @@ -64,20 +64,23 @@ */ $_ = function(sel) { + // Make a copy before adding properties + var self = dcopy($_); + //Get the DOM objects from the selector sel = $(sel); - + //Have window be default selector, just in case if(typeof sel === "undefined") { - sel = (typeof $_.el !== "undefined") - ? $_.el + sel = (typeof self.el !== "undefined") + ? self.el : window; } - $_.el = sel; + self.el = sel; - return dcopy($_); + return self; }; /**