|
|
@@ -127,6 +127,56 @@ describe('Directive v-model dynamic input type', () => {
|
|
|
expect(vm.data.text).toBe('foo')
|
|
|
}).then(done)
|
|
|
})
|
|
|
+
|
|
|
+ it('with v-bind', done => {
|
|
|
+ const vm = new Vue({
|
|
|
+ data: {
|
|
|
+ data: {
|
|
|
+ text: 'foo',
|
|
|
+ checkbox: true
|
|
|
+ },
|
|
|
+ inputs: [{ id: 'one', type: 'text' }, { id: 'two', type: 'checkbox' }]
|
|
|
+ },
|
|
|
+ template: `<div>
|
|
|
+ <input v-for="i in inputs" v-bind="i" v-model="data[i.type]">
|
|
|
+ </div>`
|
|
|
+ }).$mount()
|
|
|
+ document.body.appendChild(vm.$el)
|
|
|
+
|
|
|
+ let el1 = vm.$el.children[0]
|
|
|
+ expect(el1.id).toBe('one')
|
|
|
+ expect(el1.type).toBe('text')
|
|
|
+ expect(el1.value).toBe('foo')
|
|
|
+ el1.value = 'bar'
|
|
|
+ triggerEvent(el1, 'input')
|
|
|
+ expect(vm.data.text).toBe('bar')
|
|
|
+
|
|
|
+ let el2 = vm.$el.children[1]
|
|
|
+ expect(el2.id).toBe('two')
|
|
|
+ expect(el2.type).toBe('checkbox')
|
|
|
+ expect(el2.checked).toBe(true)
|
|
|
+ el2.click()
|
|
|
+ expect(vm.data.checkbox).toBe(false)
|
|
|
+
|
|
|
+ // now in reverse!
|
|
|
+ vm.inputs.reverse()
|
|
|
+ waitForUpdate(() => {
|
|
|
+ el1 = vm.$el.children[0]
|
|
|
+ expect(el1.id).toBe('two')
|
|
|
+ expect(el1.type).toBe('checkbox')
|
|
|
+ expect(el1.checked).toBe(false)
|
|
|
+ el1.click()
|
|
|
+ expect(vm.data.checkbox).toBe(true)
|
|
|
+
|
|
|
+ el2 = vm.$el.children[1]
|
|
|
+ expect(el2.id).toBe('one')
|
|
|
+ expect(el2.type).toBe('text')
|
|
|
+ expect(el2.value).toBe('bar')
|
|
|
+ el2.value = 'foo'
|
|
|
+ triggerEvent(el2, 'input')
|
|
|
+ expect(vm.data.text).toBe('foo')
|
|
|
+ }).then(done)
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
function assertInputWorks (vm, type, chain) {
|