Vue-test-utils: Mounted functional component has undefined context.children

Created on 27 Oct 2017  ·  9Comments  ·  Source: vuejs/vue-test-utils

Version: beta 3

Mounting a functional component passing options.context.children, results in context.children to be undefined in the components render function.

image

Console output

image

What is curious is that data.children contains the expected array.

bug feature request

All 9 comments

Taking a look in lib/create-instance.js , if options.context.children is passed as a third argument then context.children is defined, i'm not exactly sure why this works or what h in the functional components render context refers to?

h is an alias for the createElement function

Can you create a failing test?

@eddyerburgh Ah nice. Yeah will do when i'm home from work.

What are your thoughts on adding options.context.children as a third parameter in create-instance.js?

@eddyerburgh sorry for the delay, i've added a test case.

Fixed in 5fc1c57bf5d14d0425b748f9a3f42d6eb59791e2

@eddyerburgh I noticed at work this morning, that whilst _text_ children are rendered correctly, elements and components relying on createElement h => <div>hello</div> are not. This is partly my fault, as the original test case I raised only included a text child.

I think the issue is here where the children array is passed to createElement. The array should be mapped and any items which are a function should be executed (as detailed here) like so,

image

Do you want me to take care of this?

It would be great if you could take care of it 🙂

Should also update documentation (currently it seems that children is an Object and directly under options (instead of being nested under context).

Would you be able to makr a PR @andreasvirkus ?

Was this page helpful?
0 / 5 - 0 ratings