Evan You 11 år sedan
förälder
incheckning
3e7cb92ea6
2 ändrade filer med 54 tillägg och 1 borttagningar
  1. 4 1
      src/directives/if.js
  2. 50 0
      test/unit/specs/directives/if_spec.js

+ 4 - 1
src/directives/if.js

@@ -90,7 +90,10 @@ module.exports = {
       var next
       while (next !== end) {
         next = cur.nextSibling
-        if (cur.contains && cur.contains(c.$el)) {
+        if (
+          cur === c.$el ||
+          cur.contains && cur.contains(c.$el)
+        ) {
           return true
         }
         cur = next

+ 50 - 0
test/unit/specs/directives/if_spec.js

@@ -276,6 +276,56 @@ if (_.inBrowser) {
         expect(el.innerHTML).toBe(markup)
       }
     })
+    
+    // #893 in IE textNodes do not have `contains` method
+    it('call attach/detach: comparing textNodes in IE', function (done) {
+      document.body.appendChild(el)
+      var attachSpy = jasmine.createSpy('attached')
+      var detachSpy = jasmine.createSpy('detached')
+      var vm = new Vue({
+        el: el,
+        data: {
+          show: true
+        },
+        template: '<template v-if="show"><test></test></template>',
+        components: {
+          test: {
+            template: 'hi',
+            replace: true,
+            attached: attachSpy,
+            detached: detachSpy
+          }
+        }
+      })
+      assertMarkup()
+      assertCalls(1, 0)
+      vm.show = false
+      _.nextTick(function () {
+        assertMarkup()
+        assertCalls(1, 1)
+        vm.show = true
+        _.nextTick(function () {
+          assertMarkup()
+          assertCalls(2, 1)
+          vm.show = false
+          _.nextTick(function () {
+            assertMarkup()
+            assertCalls(2, 2)
+            document.body.removeChild(el)
+            done()
+          })
+        })
+      })
+
+      function assertMarkup () {
+        expect(el.innerHTML).toBe(vm.show ? 'hi' : '')
+      }
+
+      function assertCalls (attach, detach) {
+        expect(attachSpy.calls.count()).toBe(attach)
+        expect(detachSpy.calls.count()).toBe(detach)
+      }
+    })
 
   })
 }