Skip to content

Commit b6d5399

Browse files
authored
fix(runtime-vapor): properly normalize emits options if emits is an array (#12614)
1 parent 0b7f508 commit b6d5399

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/runtime-vapor/__tests__/componentEmits.spec.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,17 @@ describe('component: emit', () => {
195195
).not.toHaveBeenWarned()
196196
})
197197

198-
test.todo('validator warning', () => {
199-
// TODO: warning validator
198+
test('validator warning', () => {
199+
define({
200+
emits: {
201+
foo: (arg: number) => arg > 0,
202+
},
203+
setup(_, { emit }) {
204+
emit('foo', -1)
205+
return []
206+
},
207+
}).render()
208+
expect(`event validation failed for event "foo"`).toHaveBeenWarned()
200209
})
201210

202211
test('.once', () => {
@@ -415,8 +424,4 @@ describe('component: emit', () => {
415424
await nextTick()
416425
expect(fn).not.toHaveBeenCalled()
417426
})
418-
419-
// NOTE: not supported mixins
420-
// test.todo('merge string array emits', async () => {})
421-
// test.todo('merge object emits', async () => {})
422427
})

packages/runtime-vapor/src/componentEmits.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function normalizeEmitsOptions(
1818
let normalized: ObjectEmitsOptions
1919
if (isArray(raw)) {
2020
normalized = {}
21-
for (const key in raw) normalized[key] = null
21+
for (const key of raw) normalized[key] = null
2222
} else {
2323
normalized = raw
2424
}

0 commit comments

Comments
 (0)