diff --git a/src/mount.ts b/src/mount.ts index f19a40923..dfb9d974f 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -237,6 +237,11 @@ export function mount( isLegacyFunctionalComponent(originalComponent) ) { component = defineComponent({ + compatConfig: { + MODE: 3, + INSTANCE_LISTENERS: false, + INSTANCE_ATTRS_CLASS_STYLE: false + }, setup: (_, { attrs, slots }) => () => diff --git a/src/utils/vueCompatSupport.ts b/src/utils/vueCompatSupport.ts index 8334b6b3d..ea17229f6 100644 --- a/src/utils/vueCompatSupport.ts +++ b/src/utils/vueCompatSupport.ts @@ -32,10 +32,10 @@ export function isLegacyFunctionalComponent(component: unknown) { return false } - return ( + return Boolean( component && - typeof component === 'object' && - hasOwnProperty(component, 'functional') && - component.functional + typeof component === 'object' && + hasOwnProperty(component, 'functional') && + component.functional ) } diff --git a/tests-compat/compat.spec.ts b/tests-compat/compat.spec.ts index f922602c0..cc0ac085b 100644 --- a/tests-compat/compat.spec.ts +++ b/tests-compat/compat.spec.ts @@ -143,4 +143,35 @@ describe('@vue/compat build', () => { expect(wrapper.vm.foo).toBe('bar') }) + + it('correctly passes all props to functional component', async () => { + configureCompat({ + MODE: 3, + INSTANCE_LISTENERS: 'suppress-warning', + INSTANCE_ATTRS_CLASS_STYLE: 'suppress-warning' + }) + + const FunctionalComponent = { + functional: true, + render(h: any, context: any) { + return h('div', context.data, context.props.text) + } + } + + const onClick = jest.fn() + const wrapper = mount(FunctionalComponent, { + props: { + class: 'foo', + text: 'message', + style: { color: 'red' }, + onClick + } + }) + expect(wrapper.text()).toBe('message') + await wrapper.trigger('click') + expect(onClick).toHaveBeenCalled() + expect(wrapper.html()).toBe( + '