Skip to content

Commit

Permalink
fix(stubs): avoid warning on normalized props with Vue v3.4.22
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cexbrayat committed Apr 16, 2024
1 parent ea8654b commit 05d9745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/vnodeTransformers/stubComponentsTransformer.ts
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
@@ -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

0 comments on commit 05d9745

Please sign in to comment.