]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(runtime-test): add more tests (#194)
authorDmitry Sharshakov <d3dx12.xx@gmail.com>
Fri, 11 Oct 2019 01:53:15 +0000 (04:53 +0300)
committerEvan You <yyx990803@gmail.com>
Fri, 11 Oct 2019 01:53:15 +0000 (21:53 -0400)
packages/runtime-test/__tests__/testRuntime.spec.ts

index a7fe97fd9297617c143b3213844454db59efb87a..22a813cbaa58c677f8be6aabf738b1ad03cb729a 100644 (file)
@@ -12,10 +12,13 @@ import {
   NodeOpTypes,
   nextTick,
   serialize,
-  triggerEvent
+  triggerEvent,
+  mockWarn
 } from '../src'
 
 describe('test renderer', () => {
+  mockWarn()
+
   it('should work', () => {
     const root = nodeOps.createElement('div')
     render(
@@ -169,4 +172,47 @@ describe('test renderer', () => {
     await nextTick()
     expect(serialize(root)).toBe(`<div><span>1</span></div>`)
   })
+
+  it('should be able to trigger events with muliple listeners', async () => {
+    const count = ref(0)
+    const count2 = ref(1)
+
+    const App = () => {
+      return h(
+        'span',
+        {
+          onClick: [
+            () => {
+              count.value++
+            },
+            () => {
+              count2.value++
+            }
+          ]
+        },
+        `${count.value}, ${count2.value}`
+      )
+    }
+
+    const root = nodeOps.createElement('div')
+    render(h(App), root)
+    triggerEvent(root.children[0] as TestElement, 'click')
+    expect(count.value).toBe(1)
+    expect(count2.value).toBe(2)
+    await nextTick()
+    expect(serialize(root)).toBe(`<div><span>1, 2</span></div>`)
+  })
+
+  it('should mock warn', () => {
+    console.warn('warn!!!')
+    expect('warn!!!').toHaveBeenWarned()
+    expect('warn!!!').toHaveBeenWarnedTimes(1)
+
+    console.warn('warn!!!')
+    expect('warn!!!').toHaveBeenWarnedTimes(2)
+
+    console.warn('warning')
+    expect('warn!!!').toHaveBeenWarnedTimes(2)
+    expect('warning').toHaveBeenWarnedLast()
+  })
 })