Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/util/props.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { warn } from './debug'
import { observe, toggleObserving, shouldObserve } from '../observer/index'
import { isRef } from '../../v3'
import {
hasOwn,
isArray,
Expand Down Expand Up @@ -109,6 +110,7 @@ function assertProp(
vm?: Component,
absent?: boolean
) {
value = isRef(value) ? value.value : value
if (prop.required && absent) {
warn('Missing required prop: "' + name + '"', vm)
return
Expand Down
33 changes: 33 additions & 0 deletions test/unit/features/options/props.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import { hasSymbol } from 'core/util/env'
import testObjectOption from '../../../helpers/test-object-option'
import { ref, h } from 'v3'

describe('Options props', () => {
testObjectOption('props')
Expand Down Expand Up @@ -593,4 +594,36 @@ describe('Options props', () => {
'Invalid prop type: "String" is not a constructor'
).toHaveBeenWarned()
})

// #12930
it('should work with ref unwrap', function () {
function makeInstance(value, type) {
const Comp = {
props: {
msg: {
type
}
},
setup() {
return () => h('div')
}
}
const App = {
setup() {
const msg = ref(value)
return () => h(Comp, { props: { msg } })
}
}
return new Vue(App).$mount()
}

makeInstance('123', String)
expect((console.error as any).mock.calls.length).toBe(0)
makeInstance('123', Object)
expect('Expected Object, got String with value "123"').toHaveBeenWarned()
makeInstance('123', Number)
expect(
'Expected Number with value 123, got String with value "123"'
).toHaveBeenWarned()
})
})