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(stubs): avoid warning on normalized props with Vue v3.4.22 #2413

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vnodeTransformers/stubComponentsTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const normalizeStubProps = (props: ComponentPropsOptions) => {
const $props = props as unknown as ComponentObjectPropsOptions
return Object.keys($props).reduce((acc, key) => {
if (typeof $props[key] === 'symbol') {
return { ...acc, [key]: $props[key]?.toString() }
return { ...acc, [key]: [$props[key]?.toString()] }
}
if (typeof $props[key] === 'function') {
return { ...acc, [key]: '[Function]' }
return { ...acc, [key]: ['[Function]'] }
}
return { ...acc, [key]: $props[key] }
}, {})
Expand Down
16 changes: 15 additions & 1 deletion tests/props.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { mount, shallowMount, VueWrapper } from '../src'
import WithProps from './components/WithProps.vue'
import PropWithSymbol from './components/PropWithSymbol.vue'
Expand Down Expand Up @@ -318,6 +318,20 @@ describe('props', () => {
expect(wrapper.html()).toBe('<comp-stub fn="[Function]"></comp-stub>')
})

// https://github.com/vuejs/test-utils/issues/2411
it('should not warn on stringify props in stubs', () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue()
const Comp = defineComponent({
name: 'Comp',
template: `<transition @enter="() => {}"></transition>`
})

const wrapper = mount(Comp)

expect(wrapper.html()).toContain('<transition-stub')
expect(spy).not.toHaveBeenCalled()
})

describe('edge case with symbol props and stubs', () => {
it('works with Symbol as default', () => {
const Comp = defineComponent({
Expand Down