Skip to content

Commit c62068f

Browse files
committed
fix: find/stub anonymous component
1 parent 021b423 commit c62068f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/stubs.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ export function stubComponents(
7575
shallow: boolean = false
7676
) {
7777
transformVNodeArgs((args) => {
78+
const locallyRegisteredComponents = (args[0] as any).components as
79+
| Record<string, VNodeTypes>
80+
| undefined
81+
if (locallyRegisteredComponents) {
82+
for (const registrationName in locallyRegisteredComponents) {
83+
const component = locallyRegisteredComponents[registrationName]
84+
if (!component['name'] && !component['displayName']) {
85+
component['name'] = registrationName
86+
}
87+
}
88+
}
7889
const [nodeType, props, children, patchFlag, dynamicProps] = args
7990
const type = nodeType as VNodeTypes
8091
// args[0] can either be:

tests/shallowMount.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('shallowMount', () => {
2626
)
2727
})
2828

29-
it.only('stubs all components, but allows providing custom stub', () => {
29+
it('stubs all components, but allows providing custom stub', () => {
3030
const wrapper = mount(ComponentWithChildren, {
3131
shallow: true,
3232
global: {

0 commit comments

Comments
 (0)