Skip to content

Commit

Permalink
fix(shallow): correctly stub anonymous components
Browse files Browse the repository at this point in the history
  • Loading branch information
xanf committed Jun 30, 2021
1 parent 63e1c6d commit 2d00f3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ export function stubComponents(
const registeredName = getComponentRegisteredName(instance, type)
const componentName = type['name'] || type['displayName']

// No name found?
if (!registeredName && !componentName) {
return renderStubDefaultSlot || !shallow ? args : ['stub']
}

let stub = null
let name = null

Expand Down
24 changes: 24 additions & 0 deletions tests/mountingOptions/global.stubs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,28 @@ describe('mounting options: stubs', () => {
)
})
})

it('renders stub for anonymous component when using shallow mount', () => {
const AnonymousComponent = defineComponent({
template: `<div class="original"><slot></slot></div>`
})

const WrapperComponent = defineComponent({
computed: {
cmp() {
return AnonymousComponent
}
},
template: `<component :is="cmp">test</component>`
})

const wrapper = mount(WrapperComponent, {
shallow: true,
global: {
renderStubDefaultSlot: true
}
})

expect(wrapper.html()).toBe('<stub>test</stub>')
})
})

0 comments on commit 2d00f3a

Please sign in to comment.