Skip to content

Commit 4108a43

Browse files
Fix: Use defaultName when it exists to correctly stub async components (#1136)
* fix: give defaultName precedence * chore: add unit test for async component stub * chore: import from vue instead of vue/compat * chore: make linter happy Co-authored-by: Evert van der Weit <[email protected]>
1 parent 5e675b1 commit 4108a43

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/stubs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const getComponentName = (instance: any | null, type: VNodeTypes): string => {
138138
(key) => instance.setupState[key] === type
139139
)
140140

141-
return type.name || defaultName || ''
141+
return defaultName || type.name || ''
142142
}
143143

144144
if (isLegacyExtendedComponent(type)) {

tests/components/ScriptSetupWithChildren.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<script setup lang="ts">
2+
import { defineAsyncComponent } from 'vue'
3+
24
import Hello from './Hello.vue'
35
import ComponentWithInput from './ComponentWithInput.vue'
46
import ComponentWithoutName from './ComponentWithoutName.vue'
7+
const ComponentAsync = defineAsyncComponent(
8+
() => import('./ComponentWithoutName.vue')
9+
)
510
import ScriptSetup from './ScriptSetup.vue'
611
import WithProps from './WithProps.vue'
712
</script>
@@ -10,6 +15,7 @@ import WithProps from './WithProps.vue'
1015
<hello />
1116
<component-with-input />
1217
<component-without-name />
18+
<component-async />
1319
<script-setup />
1420
<with-props />
1521
</template>

tests/shallowMount.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ describe('shallowMount', () => {
161161
'<div>Override</div>\n' +
162162
'<component-with-input-stub></component-with-input-stub>\n' +
163163
'<component-without-name-stub></component-without-name-stub>\n' +
164+
'<component-async-stub></component-async-stub>\n' +
164165
'<script-setup-stub></script-setup-stub>\n' +
165166
'<with-props-stub></with-props-stub>'
166167
)

0 commit comments

Comments
 (0)