import Vue from 'vue' describe('Directive v-for', () => { it('should travel array of primitive values', done => { const vm = new Vue({ el: '#app', template: `
{{i}}-{{item}}
`, data: { list: ['a', 'b', 'c'] } }) expect(vm.$el.innerHTML).toBe('0-a1-b2-c') Vue.set(vm.list, 0, 'd') waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('0-d1-b2-c') vm.list.push('d') }).then(() => { expect(vm.$el.innerHTML).toBe('0-d1-b2-c3-d') vm.list.splice(1, 2) }).then(() => { expect(vm.$el.innerHTML).toBe('0-d1-d') vm.list = ['x', 'y'] }).then(() => { expect(vm.$el.innerHTML).toBe('0-x1-y') done() }).catch(done) }) it('should travel array of object values', done => { const vm = new Vue({ el: '#app', template: `
{{i}}-{{item.value}}
`, data: { list: [ { value: 'a' }, { value: 'b' }, { value: 'c' } ] } }) expect(vm.$el.innerHTML).toBe('0-a1-b2-c') Vue.set(vm.list, 0, { value: 'd' }) waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('0-d1-b2-c') vm.list[0].value = 'e' }).then(() => { expect(vm.$el.innerHTML).toBe('0-e1-b2-c') vm.list.push({}) }).then(() => { expect(vm.$el.innerHTML).toBe('0-e1-b2-c3-') vm.list.splice(1, 2) }).then(() => { expect(vm.$el.innerHTML).toBe('0-e1-') vm.list = [{ value: 'x' }, { value: 'y' }] }).then(() => { expect(vm.$el.innerHTML).toBe('0-x1-y') done() }).catch(done) }) it('should travel each key of an object', done => { const vm = new Vue({ el: '#app', template: `
{{v}}-{{k}}
`, data: { obj: { a: 0, b: 1, c: 2 } } }) expect(vm.$el.innerHTML).toBe('0-a1-b2-c') vm.obj.a = 3 waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('3-a1-b2-c') Vue.set(vm.obj, 'd', 4) }).then(() => { expect(vm.$el.innerHTML).toBe('3-a1-b2-c4-d') Vue.delete(vm.obj, 'a') }).then(() => { expect(vm.$el.innerHTML).toBe('1-b2-c4-d') done() }).catch(done) }) it('should travel each key of data', done => { const vm = new Vue({ el: '#app', template: `
{{v}}-{{k}}
`, data: { a: 0, b: 1, c: 2 } }) expect(vm.$el.innerHTML).toBe('0-a1-b2-c') vm.a = 3 waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('3-a1-b2-c') Vue.set(vm, 'd', 4) }).then(() => { expect(vm.$el.innerHTML).toBe('3-a1-b2-c4-d') Vue.delete(vm, 'a') }).then(() => { expect(vm.$el.innerHTML).toBe('1-b2-c4-d') done() }).catch(done) }) })