Skip to content

Commit cb05d9d

Browse files
committed
feat(options.children): add option to pass children to functional components
1 parent 5dc0010 commit cb05d9d

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
lines changed

flow/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ declare type Options = { // eslint-disable-line no-undef
55
localVue?: Component,
66
stubs?: Object,
77
context?: Object,
8-
clone?: boolean
8+
clone?: boolean,
9+
children?: Array<Component | string>
910
}

src/lib/create-instance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function createConstructor (component: Component, options: Option
2222
const clonedComponent = cloneDeep(component)
2323
component = {
2424
render (h) {
25-
return h(clonedComponent, options.context)
25+
return h(clonedComponent, options.context, options.children)
2626
}
2727
}
2828
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import mount from '~src/mount'
2+
3+
describe('mount.children', () => {
4+
it('mounts functional component with children when passed children array', () => {
5+
const Component = {
6+
functional: true,
7+
render (h, { children }) {
8+
return h('div', children)
9+
},
10+
name: 'common'
11+
}
12+
13+
const context = {}
14+
const children = [
15+
'hello'
16+
]
17+
18+
const wrapper = mount(Component, { context, children })
19+
20+
expect(wrapper.text()).to.contain('hello')
21+
})
22+
})

test/integration/specs/mount/options/context.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mount from '~src/mount'
22

3-
describe('context', () => {
3+
describe('mount.context', () => {
44
it('mounts functional component when passed context object', () => {
55
const Component = {
66
functional: true,

types/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type Stubs = {
2525
[key: string]: Component | string | true
2626
} | string[]
2727

28+
type Children = (Component | string)[]
29+
2830
/**
2931
* Base class of Wrapper and WrapperArray
3032
* It has common methods on both Wrapper and WrapperArray
@@ -85,7 +87,8 @@ interface MountOptions<V extends Vue> extends ComponentOptions<V> {
8587
localVue?: typeof Vue
8688
intercept?: object
8789
slots?: Slots
88-
stubs?: Stubs
90+
stubs?: Stubs,
91+
children?: Children
8992
}
9093

9194
type ShallowOptions<V extends Vue> = MountOptions<V>

types/test/mount.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mount(functionalOptions, {
4646
context: {
4747
props: { foo: 'test' }
4848
},
49+
children: ['child', ClassComponent],
4950
stubs: ['child']
5051
})
5152

0 commit comments

Comments
 (0)