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 ca51437
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 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('<anonymous-stub>test</anonymous-stub>')
})
})
4 changes: 2 additions & 2 deletions tests/shallowMount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ describe('shallowMount', () => {
expect(wrapper.html()).toEqual(
'<div>Override</div>\n' +
'<component-with-input-stub></component-with-input-stub>\n' +
'<stub></stub>\n' +
'<stub></stub>\n' +
'<anonymous-stub></anonymous-stub>\n' +
'<anonymous-stub></anonymous-stub>\n' +
'<with-props-stub></with-props-stub>'
)
})
Expand Down

0 comments on commit ca51437

Please sign in to comment.