]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-vapor): properly normalize emits options if emits is an array (#12614)
authoredison <daiwei521@126.com>
Tue, 28 Jan 2025 09:04:48 +0000 (17:04 +0800)
committerGitHub <noreply@github.com>
Tue, 28 Jan 2025 09:04:48 +0000 (17:04 +0800)
packages/runtime-vapor/__tests__/componentEmits.spec.ts
packages/runtime-vapor/src/componentEmits.ts

index 7c3bfe69ed4641639be46ff0dc71cf3c828311df..8c8a56085bafbc7eb0a11fd688f345cd6b442416 100644 (file)
@@ -195,8 +195,17 @@ describe('component: emit', () => {
     ).not.toHaveBeenWarned()
   })
 
-  test.todo('validator warning', () => {
-    // TODO: warning validator
+  test('validator warning', () => {
+    define({
+      emits: {
+        foo: (arg: number) => arg > 0,
+      },
+      setup(_, { emit }) {
+        emit('foo', -1)
+        return []
+      },
+    }).render()
+    expect(`event validation failed for event "foo"`).toHaveBeenWarned()
   })
 
   test('.once', () => {
@@ -415,8 +424,4 @@ describe('component: emit', () => {
     await nextTick()
     expect(fn).not.toHaveBeenCalled()
   })
-
-  // NOTE: not supported mixins
-  // test.todo('merge string array emits', async () => {})
-  // test.todo('merge object emits', async () => {})
 })
index dc49ba6b1b5af602914ca05fd27a5a21e0b03ecc..68b7cfbeb21cf6e40d90a1a19d06718296629565 100644 (file)
@@ -18,7 +18,7 @@ export function normalizeEmitsOptions(
   let normalized: ObjectEmitsOptions
   if (isArray(raw)) {
     normalized = {}
-    for (const key in raw) normalized[key] = null
+    for (const key of raw) normalized[key] = null
   } else {
     normalized = raw
   }