Skip to content

Commit

Permalink
test: Add failing tests for shallowMount issue with dynamic components
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Hudson committed Feb 14, 2022
1 parent 67a3e7a commit 254bd9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/components/DynamicComponentWithComputedProperty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<component :is="Hello" />
</template>

<script setup lang="ts">
import { computed } from 'vue'
import Hello from './Hello.vue'
import ComponentWithChildren from './ComponentWithChildren.vue'
interface Props {
isHello?: boolean
}
const props = defineProps<Props>()
const computedProperty = computed(() => {
return props.isHello ? Hello : ComponentWithChildren
})
</script>
17 changes: 17 additions & 0 deletions tests/shallowMount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineAsyncComponent, defineComponent } from 'vue'
import { mount, shallowMount, VueWrapper } from '../src'
import ComponentWithChildren from './components/ComponentWithChildren.vue'
import ScriptSetupWithChildren from './components/ScriptSetupWithChildren.vue'
import DynamicComponentWithComputedProperty from './components/DynamicComponentWithComputedProperty.vue'

describe('shallowMount', () => {
it('renders props for stubbed component in a snapshot', () => {
Expand Down Expand Up @@ -196,4 +197,20 @@ describe('shallowMount', () => {
'</div>'
)
})

it('stubs a given dynamic component returned by a computed property', () => {
const wrapper = shallowMount(DynamicComponentWithComputedProperty, {
props: { isHello: true }
})

expect(wrapper.find('hello-stub').exists()).toBe(true)
})

it('does not attempt to stub a dynamic component based on the name of a computed property', () => {
const wrapper = shallowMount(DynamicComponentWithComputedProperty, {
props: { isHello: true }
})

expect(wrapper.find('computed-property-stub').exists()).toBe(false)
})
})

0 comments on commit 254bd9e

Please sign in to comment.