Skip to content

Commit

Permalink
fix(runtime-core): fix kebab-case prop required warning
Browse files Browse the repository at this point in the history
fix #3495
ref #3363
  • Loading branch information
yyx990803 committed Mar 27, 2021
1 parent 37c1709 commit 2121c32
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,25 @@ describe('component props', () => {
expect(`Missing required prop: "num"`).toHaveBeenWarned()
})

// #3495
test('should not warn required props using kebab-case', async () => {
const Comp = {
props: {
fooBar: { type: String, required: true }
},
setup() {
return () => null
}
}
render(
h(Comp, {
'foo-bar': 'hello'
}),
nodeOps.createElement('div')
)
expect(`Missing required prop: "fooBar"`).not.toHaveBeenWarned()
})

test('merging props from mixins and extends', () => {
let setupProps: any
let renderProxy: any
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,12 @@ function validateProps(
for (const key in options) {
let opt = options[key]
if (opt == null) continue
validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key))
validateProp(
key,
resolvedValues[key],
opt,
!hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key))
)
}
}

Expand Down

0 comments on commit 2121c32

Please sign in to comment.