Skip to content

Commit 1a9dc0a

Browse files
committed
improve test
1 parent bb24a36 commit 1a9dc0a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<template>
2-
<div foo="bar"><span baz="qux">{{ quux }}</span></div>
2+
<div><span baz="qux">{{ fromLocalVue }},{{ bar }}</span></div>
33
</template>
44

55
<script>
66
export default{
77
name: 'component-with-parent-name',
8+
props: ['fromLocalVue'],
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

+12-6
Original file line numberDiff line numberDiff line change
@@ -573,17 +573,17 @@ describeWithMountingMethods('options.slots', mountingMethod => {
573573

574574
itDoNotRunIf(
575575
mountingMethod.name === 'renderToString',
576-
'sets a component which can access the parent component',
576+
'sets a component which can access the parent component and the child component',
577577
() => {
578578
const localVue = createLocalVue()
579579
localVue.prototype.bar = 'FOO'
580-
const wrapperComponent = mount(
580+
const ParentComponent = mount(
581581
{
582582
name: 'parentComponent',
583583
template: '<div><slot /></div>',
584584
data () {
585585
return {
586-
childName: ''
586+
childComponentName: ''
587587
}
588588
}
589589
},
@@ -592,13 +592,19 @@ describeWithMountingMethods('options.slots', mountingMethod => {
592592
ComponentWithParentName
593593
},
594594
slots: {
595-
default: '<component-with-parent-name :foo="bar" />'
595+
default: [
596+
'<component-with-parent-name :fromLocalVue="bar" />',
597+
'<component-with-parent-name :fromLocalVue="bar" />'
598+
]
596599
},
597600
localVue
598601
}
599602
)
600-
expect(wrapperComponent.vm.childName).to.equal('component-with-parent-name')
601-
expect(wrapperComponent.html()).to.equal('<div><div foo="FOO"><span baz="qux">quux</span></div></div>')
603+
const childComponentName = 'component-with-parent-name'
604+
expect(ParentComponent.vm.childComponentName).to.equal(childComponentName)
605+
expect(ParentComponent.vm.$children.length).to.equal(2)
606+
expect(ParentComponent.vm.$children.every(c => c.$options.name === childComponentName)).to.equal(true)
607+
expect(ParentComponent.html()).to.equal('<div><div><span baz="qux">FOO,quux</span></div><div><span baz="qux">FOO,quux</span></div></div>')
602608
}
603609
)
604610
})

0 commit comments

Comments
 (0)