Skip to content

Components only returning a render function from setup aren't considered components #1596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LeBenLeBen opened this issue Jun 28, 2020 · 1 comment · Fixed by #1600
Closed

Comments

@LeBenLeBen
Copy link
Contributor

Subject of the issue

Components using the Composition API that return a render function from setup are not considered valid Vue Components by the internal validator. Consequently, they can’t be used as stubs.

Steps to reproduce

Have a component using the composition API without template and where the render function is returned by the setup function:

import { defineComponent, createElement } from '@vue/composition-api';

export default defineComponent({
  name: 'CFlexItem',

  setup(props, { slots }) {
    return () => {
      return createElement("div", {}, slots.default && slots.default());
    };
  },
});

When trying to mount it like this:

import CFlex from './CFlex';
import CFlexItem from './CFlexItem';

mount(CFlex, {
  stubs: {
    CFlexItem
  },
  slots: {
    default: [
      '<CFlexItem>1</CFlexItem>',
      '<CFlexItem>2</CFlexItem>',
      '<CFlexItem>3</CFlexItem>',
    ],
  },
});

Vue-test-utils throws the following error:

[vue-test-utils]: options.stub values must be passed a string or component

Theses components’ code can be found here.

Expected behaviour

Vue components using solely a render function through setup should be considered valid components.

Possible Solution

Adapt isVueComponent method to handle this specific kind of components. But I’m not sure how this should be done, hints welcome so I can potentially submit a PR.

@lmiller1990
Copy link
Member

You could try just adding another condition to isVueComponent. Check if setup exists, and render does not.

I have no idea what will happen - this easiest way to find out would just be going to node_modules/@vue/test-utils/vue-test-utils.js (it is not minified) and adding that in and running your test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants