Skip to content

Commit f197d0d

Browse files
gebilaoxiongyyx990803
authored andcommitted
test:add bind object test
1 parent d33c125 commit f197d0d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

Diff for: test/unit/features/directives/bind.spec.js

+56
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,60 @@ describe('Directive v-bind', () => {
325325
expect(vm.$el.children[0].getAttribute('data-test')).toBe(null)
326326
}).then(done)
327327
})
328+
329+
describe('bind object with special attribute', () => {
330+
function makeInstance (options) {
331+
return new Vue({
332+
template: `<div>${options.parentTemp}</div>`,
333+
data: {
334+
attrs: {
335+
[options.attr]: options.value
336+
}
337+
},
338+
components: {
339+
comp: {
340+
template: options.childTemp
341+
}
342+
}
343+
}).$mount()
344+
}
345+
346+
it('key', () => {
347+
const vm = makeInstance({
348+
attr: 'key',
349+
value: 'test',
350+
parentTemp: '<div v-bind="attrs"></div>'
351+
})
352+
expect(vm._vnode.children[0].key).toBe('test')
353+
})
354+
355+
it('ref', () => {
356+
const vm = makeInstance({
357+
attr: 'ref',
358+
value: 'test',
359+
parentTemp: '<div v-bind="attrs"></div>'
360+
})
361+
expect(vm.$refs.test).toBe(vm.$el.firstChild)
362+
})
363+
364+
it('slot', () => {
365+
const vm = makeInstance({
366+
attr: 'slot',
367+
value: 'test',
368+
parentTemp: '<comp><span v-bind="attrs">123</span></comp>',
369+
childTemp: '<div>slot:<slot name="test"></slot></div>'
370+
})
371+
expect(vm.$el.innerHTML).toBe('<div>slot:<span>123</span></div>')
372+
})
373+
374+
it('is', () => {
375+
const vm = makeInstance({
376+
attr: 'is',
377+
value: 'comp',
378+
parentTemp: '<component v-bind="attrs"></component>',
379+
childTemp: '<div>comp</div>'
380+
})
381+
expect(vm.$el.innerHTML).toBe('<div>comp</div>')
382+
})
383+
})
328384
})

0 commit comments

Comments
 (0)