فهرست منبع

remove classList from unit test

Evan You 12 سال پیش
والد
کامیت
11e1a25f5b
3فایلهای تغییر یافته به همراه10 افزوده شده و 99 حذف شده
  1. 0 1
      test/unit/runner.html
  2. 10 5
      test/unit/specs/directives.js
  3. 0 93
      test/unit/utils/classList.js

+ 0 - 1
test/unit/runner.html

@@ -14,7 +14,6 @@
         <!-- include test utilities -->
         <script src="utils/mocha.js"></script>
         <script src="utils/chai.js"></script>
-        <script src="utils/classList.js"></script>
         <script src="utils/prepare.js"></script>
 
         <!-- specs -->

+ 10 - 5
test/unit/specs/directives.js

@@ -169,22 +169,27 @@ describe('UNIT: Directives', function () {
 
     describe('class', function () {
 
+        function contains (el, cls) {
+            var cur = ' ' + el.className + ' '
+            return cur.indexOf(' ' + cls + ' ') > -1
+        }
+
         it('should set class to the value if it has no arg', function () {
             var dir = mockDirective('class')
             dir.update('test')
-            assert.ok(dir.el.classList.contains('test'))
+            assert.ok(contains(dir.el, 'test'))
             dir.update('hoho')
-            assert.ok(!dir.el.classList.contains('test'))
-            assert.ok(dir.el.classList.contains('hoho'))
+            assert.ok(!contains(dir.el, 'test'))
+            assert.ok(contains(dir.el, 'hoho'))
         })
 
         it('should add/remove class based on truthy/falsy if it has an arg', function () {
             var dir = mockDirective('class')
             dir.arg = 'test'
             dir.update(true)
-            assert.ok(dir.el.classList.contains('test'))
+            assert.ok(contains(dir.el, 'test'))
             dir.update(false)
-            assert.ok(!dir.el.classList.contains('test'))
+            assert.ok(!contains(dir.el, 'test'))
         })
 
     })

+ 0 - 93
test/unit/utils/classList.js

@@ -1,93 +0,0 @@
-(function () {
-
-if (typeof window.Element === "undefined" || "classList" in document.documentElement) return;
-
-// adds indexOf to Array prototype for IE support
-if (!Array.prototype.indexOf) {
-    Array.prototype.indexOf = function(obj, start) {
-        for (var i = (start || 0), j = this.length; i < j; i++) {
-            if (this[i] === obj) { return i; }
-        }
-        return -1;
-    }
-}
-
-var prototype = Array.prototype,
-    indexOf = prototype.indexOf,
-    slice = prototype.slice,
-    push = prototype.push,
-    splice = prototype.splice,
-    join = prototype.join;
-
-function DOMTokenList(el) {  
-  this._element = el;
-  if (el.className != this._classCache) {
-    this._classCache = el.className;
-
-    if (!this._classCache) return;
-    
-      // The className needs to be trimmed and split on whitespace
-      // to retrieve a list of classes.
-      var classes = this._classCache.replace(/^\s+|\s+$/g,'').split(/\s+/),
-        i;
-    for (i = 0; i < classes.length; i++) {
-      push.call(this, classes[i]);
-    }
-  }
-};
-
-function setToClassName(el, classes) {
-  el.className = classes.join(' ');
-}
-
-DOMTokenList.prototype = {
-  add: function(token) {
-    if(this.contains(token)) return;
-    push.call(this, token);
-    setToClassName(this._element, slice.call(this, 0));
-  },
-  contains: function(token) {
-    return indexOf.call(this, token) !== -1;
-  },
-  item: function(index) {
-    return this[index] || null;
-  },
-  remove: function(token) {
-    var i = indexOf.call(this, token);
-     if (i === -1) {
-       return;
-     }
-    splice.call(this, i, 1);
-    setToClassName(this._element, slice.call(this, 0));
-  },
-  toString: function() {
-    return join.call(this, ' ');
-  },
-  toggle: function(token) {
-    if (!this.contains(token)) {
-      this.add(token);
-    } else {
-      this.remove(token);
-    }
-
-    return this.contains(token);
-  }
-};
-
-window.DOMTokenList = DOMTokenList;
-
-function defineElementGetter (obj, prop, getter) {
-    if (Object.defineProperty) {
-        Object.defineProperty(obj, prop,{
-            get : getter
-        })
-    } else {                    
-        obj.__defineGetter__(prop, getter);
-    }
-}
-
-defineElementGetter(Element.prototype, 'classList', function () {
-  return new DOMTokenList(this);            
-});
-
-})();