Skip to content

Functional components with multiple element roots don't mount #1092

@fsblemos

Description

@fsblemos

Version

1.0.0-beta.28

Reproduction link

https://codesandbox.io/s/zkxn8pxpm3?expanddevtools=1&module=%2Fsrc%2Fcomponents%2FHelloWorld.test.js

Steps to reproduce

Create a function component with 2 root elements and try to mount it.

What is expected?

Since functional components can have multiple root elements and works in the browser, mount and shallowMount methods should render it normally too.

What is actually happening?

The component is not mounting and console throws an error (which is not thrown in the browser).

Activity

fsblemos

fsblemos commented on Jan 11, 2019

@fsblemos
Author

An workaround should wrap the component with a root element (like this) then I can test:

it('should support returning more than one root node', () => {
  const wrapper = mount({
    template: `<div><test></test></div>`,
    components: {
      test: {
        functional: true,
        render (h) {
          return [h('span', 'foo'), h('span', 'bar')]
        }
      }
    }
  });
  
  expect(wrapper.html()).toBe('<span>foo</span><span>bar</span>')
})

There is a way vue-test-utils wrap functional components with a root element and return an WrapperArray so we don't need create a root div manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @eddyerburgh@fsblemos

        Issue actions

          Functional components with multiple element roots don't mount · Issue #1092 · vuejs/vue-test-utils