]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: test for events when component updating (#7896)
authoriwusong <wusong3918@gmail.com>
Tue, 4 Jun 2024 15:04:11 +0000 (23:04 +0800)
committerGitHub <noreply@github.com>
Tue, 4 Jun 2024 15:04:11 +0000 (23:04 +0800)
test for #5517

packages/runtime-core/__tests__/componentProps.spec.ts

index 1cc43c91bc2c182ad70ed6c5850247ebaf6fdbbb..8244580005bb15672428b5dd8241c901d6920da8 100644 (file)
@@ -749,4 +749,39 @@ describe('component props', () => {
     expect(`Invalid prop name: "ref"`).toHaveBeenWarned()
     expect(`Invalid prop name: "$foo"`).toHaveBeenWarned()
   })
+
+  // #5517
+  test('events should not be props when component updating', async () => {
+    let props: any
+    function eventHandler() {}
+    const foo = ref(1)
+
+    const Child = defineComponent({
+      setup(_props) {
+        props = _props
+      },
+      emits: ['event'],
+      props: ['foo'],
+      template: `<div>{{ foo }}</div>`,
+    })
+
+    const Comp = defineComponent({
+      setup() {
+        return {
+          foo,
+          eventHandler,
+        }
+      },
+      components: { Child },
+      template: `<Child @event="eventHandler" :foo="foo" />`,
+    })
+
+    const root = document.createElement('div')
+    domRender(h(Comp), root)
+    expect(props).not.toHaveProperty('onEvent')
+
+    foo.value++
+    await nextTick()
+    expect(props).not.toHaveProperty('onEvent')
+  })
 })