Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return the correct name when stubbing a script setup component #1783

Merged
merged 4 commits into from Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -52,6 +52,7 @@
"rollup-plugin-typescript2": "0.34.0",
"tslib": "2.4.0",
"typescript": "4.8.3",
"unplugin-vue-components": "^0.22.7",
hershelh marked this conversation as resolved.
Show resolved Hide resolved
"vite": "3.1.3",
"vitepress": "0.22.4",
"vitest": "0.22.1",
Expand Down
117 changes: 114 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/utils/componentName.ts
Expand Up @@ -38,7 +38,9 @@ export const getComponentName = (
type: VNodeTypes
): string => {
if (isObjectComponent(type)) {
return getComponentNameInSetup(instance, type) || type.name || ''
return (
getComponentNameInSetup(instance, type) || type.name || type.__name || ''
hershelh marked this conversation as resolved.
Show resolved Hide resolved
)
}

if (isLegacyExtendedComponent(type)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/components/AutoImportScriptSetup.vue
@@ -0,0 +1,3 @@
<template>
<ScriptSetup/>
</template>
12 changes: 12 additions & 0 deletions tests/mountingOptions/global.stubs.spec.ts
Expand Up @@ -6,6 +6,7 @@ import Hello from '../components/Hello.vue'
import ComponentWithoutName from '../components/ComponentWithoutName.vue'
import ComponentWithSlots from '../components/ComponentWithSlots.vue'
import ScriptSetupWithChildren from '../components/ScriptSetupWithChildren.vue'
import AutoImportScriptSetup from '../components/AutoImportScriptSetup.vue'

describe('mounting options: stubs', () => {
let configStubsSave = config.global.stubs
Expand Down Expand Up @@ -393,6 +394,17 @@ describe('mounting options: stubs', () => {
)
})

it('stubs a script setup component imported by unplugin-vue-components', () => {
const wrapper = mount(AutoImportScriptSetup, {
global: {
stubs: {
ScriptSetup: true
}
}
})
expect(wrapper.html()).toBe(`<script-setup-stub></script-setup-stub>`)
})

describe('transition', () => {
it('stubs transition by default', () => {
const CompStubbedByDefault = {
Expand Down
11 changes: 10 additions & 1 deletion vitest.config.ts
Expand Up @@ -2,9 +2,18 @@ import path from 'path'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import jsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'

export default defineConfig({
plugins: [vue(), jsx()],
plugins: [
vue(),
jsx(),
Components({
hershelh marked this conversation as resolved.
Show resolved Hide resolved
dts: false,
include: /AutoImportScriptSetup\.vue$/,
dirs: ['tests/components']
})
],
define: {
__USE_BUILD__: process.env.NODE_ENV !== 'test-build',
__BROWSER__: true,
Expand Down