Skip to content

Commit d0e7bdf

Browse files
committed
improve test
1 parent 64a8be2 commit d0e7bdf

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
i<template>
2-
<div foo="bar"><span baz="qux">{{ quux }}</span></div>
1+
<template>
2+
<div><span baz="qux">{{ time }},{{ fromLocalVue }},{{ bar }}</span></div>
33
</template>
44

55
<script>
66
export default{
77
name: 'component-with-parent-name',
8+
props: ['fromLocalVue', 'time'],
89
data () {
910
return {
10-
quux: 'quux'
11+
bar: 'quux'
1112
}
1213
},
1314
mounted () {
14-
this.$parent.childName = this.$options.name
15+
this.$parent.childComponentName = this.$options.name
1516
}
1617
}
1718
</script>

test/specs/mounting-options/slots.spec.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,18 @@ describeWithMountingMethods('options.slots', mountingMethod => {
602602

603603
itDoNotRunIf(
604604
mountingMethod.name === 'renderToString',
605-
'sets a component which can access the parent component',
605+
'sets a component which can access the parent component and the child component',
606606
() => {
607607
const localVue = createLocalVue()
608608
localVue.prototype.bar = 'FOO'
609-
const wrapperComponent = mount(
609+
const ParentComponent = mount(
610610
{
611611
name: 'parentComponent',
612612
template: '<div><slot /></div>',
613613
data () {
614614
return {
615-
childName: ''
615+
time: 1,
616+
childComponentName: ''
616617
}
617618
}
618619
},
@@ -621,13 +622,24 @@ describeWithMountingMethods('options.slots', mountingMethod => {
621622
ComponentWithParentName
622623
},
623624
slots: {
624-
default: '<component-with-parent-name :foo="bar" />'
625+
default: [
626+
'<component-with-parent-name :fromLocalVue="bar" :time="time" />',
627+
'<component-with-parent-name :fromLocalVue="bar" :time="time" />'
628+
]
625629
},
626630
localVue
627631
}
628632
)
629-
expect(wrapperComponent.vm.childName).to.equal('component-with-parent-name')
630-
expect(wrapperComponent.html()).to.equal('<div><div foo="FOO"><span baz="qux">quux</span></div></div>')
633+
const childComponentName = 'component-with-parent-name'
634+
expect(ParentComponent.vm.childComponentName).to.equal(childComponentName)
635+
expect(ParentComponent.vm.$children.length).to.equal(2)
636+
expect(ParentComponent.vm.$children.every(c => c.$options.name === childComponentName)).to.equal(true)
637+
expect(ParentComponent.html()).to.equal('<div><div><span baz="qux">1,FOO,quux</span></div><div><span baz="qux">1,FOO,quux</span></div></div>')
638+
ParentComponent.vm.time = 2
639+
expect(ParentComponent.vm.childComponentName).to.equal(childComponentName)
640+
expect(ParentComponent.vm.$children.length).to.equal(2)
641+
expect(ParentComponent.vm.$children.every(c => c.$options.name === childComponentName)).to.equal(true)
642+
expect(ParentComponent.html()).to.equal('<div><div><span baz="qux">2,FOO,quux</span></div><div><span baz="qux">2,FOO,quux</span></div></div>')
631643
}
632644
)
633645
})

0 commit comments

Comments
 (0)