Skip to content

Slots are not rendered in snapshot when they are in v-expansion-panel of Vuetify #887

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
trollepierre opened this issue Aug 1, 2018 · 4 comments

Comments

@trollepierre
Copy link
Contributor

trollepierre commented Aug 1, 2018

Version

1.0.0-beta.22

Reproduction link

https://codesandbox.io/s/43k3520wmw

Steps to reproduce

Slots are not rendered in snapshot when they are in v-expansion-panel of Vuetify

<template>
  <div id="my-component">
    <v-expansion-panel>
      <v-expansion-panel-content>
        Outside slot
        <div slot="header">Pierre</div>
      </v-expansion-panel-content>
    </v-expansion-panel>
  </div>
</template>

What is expected?

<div
  id="my-component"
>
  <v-expansion-panel-stub>
    <v-expansion-panel-content-stub
      expandicon="$vuetify.icons.expand"
    >
      
        Outside slot
        <div slot="header">Header</div>
    </v-expansion-panel-content-stub>
  </v-expansion-panel-stub>
</div>

What is actually happening?

<div
  id="my-component"
>
  <v-expansion-panel-stub>
    <v-expansion-panel-content-stub
      expandicon="$vuetify.icons.expand"
    >
      
      Outside slot
      
    </v-expansion-panel-content-stub>
  </v-expansion-panel-stub>
</div>

@trollepierre trollepierre changed the title Slots are not render in snapshot when they are in v-expansion-panel of Vuetify Slots are not rendered in snapshot when they are in v-expansion-panel of Vuetify Aug 1, 2018
@eddyerburgh
Copy link
Member

We currently only render default slots for stubbed components

The change you're requesting would mean that we render every named slot component. I'll investigate.

@ferm10n
Copy link

ferm10n commented Aug 8, 2018

I was interested in this myself, and here was my solution:

Modifying https://github.com/vuejs/vue-test-utils/blob/dev/packages/shared/stub-components.js#L96

export function createBlankStub (
  originalComponent: Component,
  name: string
): Component {
  const componentOptions = typeof originalComponent === 'function'
    ? originalComponent.extendOptions
    : originalComponent
  const tagName = `${name}-stub`

  // ignoreElements does not exist in Vue 2.0.x
  if (Vue.config.ignoredElements) {
    Vue.config.ignoredElements.push(tagName)
  }

  return {
    ...getCoreProperties(componentOptions),
    render (h, context) {
      let innerContent = null
      if (context) {
        innerContent = context.children
      } else {
        innerContent = Object.keys(this.$slots).map(slotName => {
          const slot = this.$slots[slotName]
          if (slotName !== 'default') {
            return slot
          } else {
            const element = h('div', { class: `${slotName}-slot` }, slot)
            return element
          }
        })
      }
      return h(
        tagName,
        {
          attrs: componentOptions.functional ? {
            ...context.props,
            ...context.data.attrs,
            class: createClassString(
              context.data.staticClass,
              context.data.class
            )
          } : {
            ...this.$props
          }
        },
        innerContent
      )
    }
  }
}

Thoughts??

@eddyerburgh
Copy link
Member

@ferm10n yes that looks good 👍

Do you want to make a PR?

ferm10n added a commit to ferm10n/vue-test-utils that referenced this issue Aug 10, 2018
@tbsvttr
Copy link

tbsvttr commented Aug 15, 2018

This issue causes huge problems for me, because most of my component tests are broken or useless because of this. I have Vuetify components nested into each other and I also want to test if the correct content is rendered is into them.

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

No branches or pull requests

4 participants