Skip to content

Commit 05d9745

Browse files
committed
fix(stubs): avoid warning on normalized props with Vue v3.4.22
Fixes #2411 We can "trick" the warning introduced in Vue v3.4.22 (See vuejs/core@7ccd453) by using an array of strings instead of a string (as the new check allows functions and arrays, but not strings). This does not affect the rendering of the stub, and still displays `[Function]`, so it should not impact the existing tests.
1 parent ea8654b commit 05d9745

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/vnodeTransformers/stubComponentsTransformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const normalizeStubProps = (props: ComponentPropsOptions) => {
4747
const $props = props as unknown as ComponentObjectPropsOptions
4848
return Object.keys($props).reduce((acc, key) => {
4949
if (typeof $props[key] === 'symbol') {
50-
return { ...acc, [key]: $props[key]?.toString() }
50+
return { ...acc, [key]: [$props[key]?.toString()] }
5151
}
5252
if (typeof $props[key] === 'function') {
53-
return { ...acc, [key]: '[Function]' }
53+
return { ...acc, [key]: ['[Function]'] }
5454
}
5555
return { ...acc, [key]: $props[key] }
5656
}, {})

tests/props.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { describe, expect, it, vi } from 'vitest'
22
import { mount, shallowMount, VueWrapper } from '../src'
33
import WithProps from './components/WithProps.vue'
44
import PropWithSymbol from './components/PropWithSymbol.vue'
@@ -318,6 +318,20 @@ describe('props', () => {
318318
expect(wrapper.html()).toBe('<comp-stub fn="[Function]"></comp-stub>')
319319
})
320320

321+
// https://github.com/vuejs/test-utils/issues/2411
322+
it('should not warn on stringify props in stubs', () => {
323+
const spy = vi.spyOn(console, 'warn').mockReturnValue()
324+
const Comp = defineComponent({
325+
name: 'Comp',
326+
template: `<transition @enter="() => {}"></transition>`
327+
})
328+
329+
const wrapper = mount(Comp)
330+
331+
expect(wrapper.html()).toContain('<transition-stub')
332+
expect(spy).not.toHaveBeenCalled()
333+
})
334+
321335
describe('edge case with symbol props and stubs', () => {
322336
it('works with Symbol as default', () => {
323337
const Comp = defineComponent({

0 commit comments

Comments
 (0)