Skip to content

Commit 7059cff

Browse files
authored
fix: forward Ref prop on mount (#1434)
1 parent 0d63f35 commit 7059cff

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/mount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
h,
33
createApp,
44
defineComponent,
5-
reactive,
5+
shallowReactive,
66
FunctionalComponent,
77
ComponentPublicInstance,
88
ComponentOptionsWithObjectProps,
@@ -379,7 +379,7 @@ export function mount(
379379
const MOUNT_COMPONENT_REF = 'VTU_COMPONENT'
380380
// we define props as reactive so that way when we update them with `setProps`
381381
// Vue's reactivity system will cause a rerender.
382-
const props = reactive({
382+
const props = shallowReactive({
383383
...options?.attrs,
384384
...options?.propsData,
385385
...options?.props,

tests/props.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mount, shallowMount } from '../src'
22
import WithProps from './components/WithProps.vue'
33
import PropWithSymbol from './components/PropWithSymbol.vue'
44
import Hello from './components/Hello.vue'
5-
import { defineComponent, h } from 'vue'
5+
import { defineComponent, h, isRef, ref } from 'vue'
66
import Title from './components/FunctionComponent'
77

88
describe('props', () => {
@@ -157,6 +157,31 @@ describe('props', () => {
157157
expect(wrapper.find('#foo2').attributes().foo).toBe('foo2 value')
158158
})
159159

160+
it('should forward ref as raw prop', () => {
161+
const TestComponent = defineComponent({
162+
props: {
163+
refProp: {
164+
type: [Object],
165+
required: true
166+
}
167+
},
168+
setup(props) {
169+
return () =>
170+
h('div', [
171+
h('h1', isRef(props.refProp) ? 'is ref' : 'is not ref'),
172+
h('span', props.refProp.value)
173+
])
174+
}
175+
})
176+
177+
const refProp = ref('Some value')
178+
const wrapper = mount(TestComponent, {
179+
props: { refProp }
180+
})
181+
expect(wrapper.find('h1').text()).toBe('is ref')
182+
expect(wrapper.find('span').text()).toBe('Some value')
183+
})
184+
160185
it('returns reactive props on a stubbed component shallow case', async () => {
161186
const Foo = {
162187
name: 'Foo',

0 commit comments

Comments
 (0)