Просмотр исходного кода

add tests for some :class and v-bind edge cases

Evan You 10 лет назад
Родитель
Сommit
f31366c60e

+ 23 - 0
test/unit/features/directives/bind.spec.js

@@ -199,4 +199,27 @@ describe('Directive v-bind', () => {
     }).$mount()
     expect('v-bind without argument expects an Object or Array value').toHaveBeenWarned()
   })
+
+  // a vdom patch edge case where the user has several un-keyed elements of the
+  // same tag next to each other, and toggling them.
+  it('properly update for toggling un-keyed children', done => {
+    const vm = new Vue({
+      template: `
+        <div>
+          <div v-if="ok" id="a" data-test="1"></div>
+          <div v-if="!ok" id="b"></div>
+        </div>
+      `,
+      data: {
+        ok: true
+      }
+    }).$mount()
+    expect(vm.$el.children[0].id).toBe('a')
+    expect(vm.$el.children[0].getAttribute('data-test')).toBe('1')
+    vm.ok = false
+    waitForUpdate(() => {
+      expect(vm.$el.children[0].id).toBe('b')
+      expect(vm.$el.children[0].getAttribute('data-test')).toBe(null)
+    }).then(done)
+  })
 })

+ 21 - 0
test/unit/features/directives/class.spec.js

@@ -106,4 +106,25 @@ describe('Directive v-bind:class', () => {
       expect(vm.$el.className).toBe('a b')
     }).then(done)
   })
+
+  // a vdom patch edge case where the user has several un-keyed elements of the
+  // same tag next to each other, and toggling them.
+  it('properly remove staticClass for toggling un-keyed children', done => {
+    const vm = new Vue({
+      template: `
+        <div>
+          <div v-if="ok" class="a"></div>
+          <div v-if="!ok"></div>
+        </div>
+      `,
+      data: {
+        ok: true
+      }
+    }).$mount()
+    expect(vm.$el.children[0].className).toBe('a')
+    vm.ok = false
+    waitForUpdate(() => {
+      expect(vm.$el.children[0].className).toBe('')
+    }).then(done)
+  })
 })