Skip to content

Commit 588d66f

Browse files
vprimachenkoyyx990803
authored andcommitted
add unit tests for (key,val) syntax of v-for
1 parent 7e5577c commit 588d66f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/unit/specs/directives/public/for/for_spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,39 @@ if (_.inBrowser) {
595595
expect(hasWarned(_, 'Duplicate value')).toBe(true)
596596
})
597597

598+
it('key val syntax with object', function () {
599+
new Vue({
600+
el: el,
601+
template: '<div v-for="(key,val) in items">{{key}} {{val}}</div>',
602+
data: {
603+
items: {'a': 'x'}
604+
}
605+
})
606+
expect(el.innerHTML).toBe('<div>a x</div>')
607+
})
608+
609+
it('key val syntax with array', function () {
610+
new Vue({
611+
el: el,
612+
template: '<div v-for="(ind,val) in items">{{ind}} {{val}}</div>',
613+
data: {
614+
items: ['x', 'y']
615+
}
616+
})
617+
expect(el.innerHTML).toBe('<div>0 x</div><div>1 y</div>')
618+
})
619+
620+
it('key val syntax with nested v-for s', function () {
621+
new Vue({
622+
el: el,
623+
template: '<div v-for="(key,val) in items"><div v-for="(subkey,subval) in val">{{key}} {{subkey}} {{subval}}</div></div>',
624+
data: {
625+
items: {'a': {'b': 'c'}}
626+
}
627+
})
628+
expect(el.innerHTML).toBe('<div><div>a b c</div></div>')
629+
})
630+
598631
it('repeat number', function () {
599632
new Vue({
600633
el: el,

0 commit comments

Comments
 (0)