Преглед на файлове

simplify _.inDoc fix and remove unit test patch for phantomjs

Evan You преди 11 години
родител
ревизия
0cbfe05117
променени са 6 файла, в които са добавени 9 реда и са изтрити 41 реда
  1. 0 3
      gruntfile.js
  2. 9 9
      src/util/dom.js
  3. 0 23
      test/unit/lib/indoc_patch.js
  4. 0 2
      test/unit/specs/directives/component_spec.js
  5. 0 2
      test/unit/specs/directives/repeat_spec.js
  6. 0 2
      test/unit/specs/misc_spec.js

+ 0 - 3
gruntfile.js

@@ -42,12 +42,10 @@ module.exports = function (grunt) {
         files: [
           'test/unit/lib/jquery.js',
           'src/**/*.js',
-          'test/unit/lib/indoc_patch.js',
           'test/unit/specs/**/*.js'
         ],
         preprocessors: {
           'src/**/*.js': ['commonjs'],
-          'test/unit/lib/indoc_patch.js': ['commonjs'],
           'test/unit/specs/**/*.js': ['commonjs']
         },
         singleRun: true
@@ -64,7 +62,6 @@ module.exports = function (grunt) {
           reporters: ['progress', 'coverage'],
           preprocessors: {
             'src/**/*.js': ['commonjs', 'coverage'],
-            'test/unit/lib/indoc_patch.js': ['commonjs'],
             'test/unit/specs/**/*.js': ['commonjs']
           },
           coverageReporter: {

+ 9 - 9
src/util/dom.js

@@ -2,8 +2,11 @@ var config = require('../config')
 
 /**
  * Check if a node is in the document.
- * Note: document.documentElement.contains should work here but doesn't seem to
- * work properly in phantom.js making unit testing difficult.
+ * Note: document.documentElement.contains should work here
+ * but always returns false for comment nodes in phantomjs,
+ * making unit tests difficult. This is fixed byy doing the
+ * contains() check on the node's parentNode instead of
+ * the node itself.
  *
  * @param {Node} node
  * @return {Boolean}
@@ -14,13 +17,10 @@ var doc =
   document.documentElement
 
 exports.inDoc = function (node) {
-  var adown = doc.nodeType === 9 ? doc.documentElement : doc
-  var bup = node && node.parentNode
-  return doc === bup || !!( bup && bup.nodeType === 1 && (
-    adown.contains
-      ? adown.contains( bup )
-      : doc.compareDocumentPosition && doc.compareDocumentPosition( bup ) & 16
-    ));
+  var parent = node && node.parentNode
+  return doc === node ||
+    doc === parent ||
+    !!(parent && parent.nodeType === 1 && (doc.contains(parent)))
 }
 
 /**

+ 0 - 23
test/unit/lib/indoc_patch.js

@@ -1,23 +0,0 @@
-// PhantomJS always return false when using Element.contains
-// on a comment node - so we have to patch the inDoc util
-// function when running in PhantomJS.
-
-var _ = require('../../../src/util')
-var inDoc = _.inDoc
-
-_.inDoc = function (el) {
-  if (el && el.nodeType === 8) {
-    return manualInDoc(el)
-  }
-  return inDoc(el)  
-}
-
-function manualInDoc (el) {
-  while (el) {
-    if (el === document.documentElement) {
-      return true
-    }
-    el = el.parentNode
-  }
-  return false
-}

+ 0 - 2
test/unit/specs/directives/component_spec.js

@@ -1,5 +1,3 @@
-// patch inDoc
-require('../../lib/indoc_patch')
 var _ = require('../../../../src/util')
 var Vue = require('../../../../src/vue')
 

+ 0 - 2
test/unit/specs/directives/repeat_spec.js

@@ -1,5 +1,3 @@
-// patch inDoc
-require('../../lib/indoc_patch')
 var _ = require('../../../../src/util')
 var Vue = require('../../../../src/vue')
 

+ 0 - 2
test/unit/specs/misc_spec.js

@@ -1,5 +1,3 @@
-// patch inDoc
-require('../lib/indoc_patch')
 // test cases for edge cases & bug fixes
 var Vue = require('../../../src/vue')