Vue-test-utils: Can't test props on child component when it's the root element

Created on 22 May 2019  路  3Comments  路  Source: vuejs/vue-test-utils

Version

1.0.0-beta.29

Reproduction link

https://github.com/alexanderstudte/propsdatatest

Steps to reproduce

run the unit test as is -> test fails.
add empty <div> around the <Panel> in HelloWorld.vue and run the test again -> test successful

What is expected?

I should be able to test the props from the child component if it is root

What is actually happening?

I need to add an element around the child for it to be no longer root.

Most helpful comment

Came across this issue today also, the workaround I am using is to access the children.

expect(wrapper.find('some-stub-name').vm.$children[0].$props.somepropname).toStrictEqual(somepropvalue);

All 3 comments

It's also failing for me and adding a wrapping div to the component is also making the test pass. In my case, I have a presenter component inside a wrapper component. The wrapper component is listening to the events sent by the presenter component. I'm able to test that the event has been triggered, but the methods bound to the event are never called.

Came across this issue today also, the workaround I am using is to access the children.

expect(wrapper.find('some-stub-name').vm.$children[0].$props.somepropname).toStrictEqual(somepropvalue);

I am also facing the same issue and actually I observed one more thing that when I am using wrapper.props() method it gives the component's(the one which I am writing test cases of) props and when I usewrapper.attribues() I get the props of the root child component.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kjugi picture kjugi  路  3Comments

yoyoys picture yoyoys  路  3Comments

josephstein picture josephstein  路  4Comments

eddyerburgh picture eddyerburgh  路  4Comments

vilarinholeo picture vilarinholeo  路  3Comments