From a2c491b0df32801c0542bd4286791db8ead923ca Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Tue, 16 Apr 2024 10:37:55 +0200 Subject: [PATCH] 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 https://github.com/vuejs/core/commit/7ccd453dd004076cad49ec9f56cd5fe97b7b6ed8) 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. --- .../stubComponentsTransformer.ts | 4 ++-- tests/props.spec.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/vnodeTransformers/stubComponentsTransformer.ts b/src/vnodeTransformers/stubComponentsTransformer.ts index 2a9788b85..547d7875f 100644 --- a/src/vnodeTransformers/stubComponentsTransformer.ts +++ b/src/vnodeTransformers/stubComponentsTransformer.ts @@ -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] } }, {}) diff --git a/tests/props.spec.ts b/tests/props.spec.ts index 90c2948e8..7ba71b3b7 100644 --- a/tests/props.spec.ts +++ b/tests/props.spec.ts @@ -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' @@ -318,6 +318,20 @@ describe('props', () => { expect(wrapper.html()).toBe('') }) + // 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: `` + }) + + const wrapper = mount(Comp) + + expect(wrapper.html()).toContain(' { it('works with Symbol as default', () => { const Comp = defineComponent({