diff --git a/packages/runtime-test/__tests__/testRuntime.spec.ts b/packages/runtime-test/__tests__/testRuntime.spec.ts index a7fe97fd..22a813cb 100644 --- a/packages/runtime-test/__tests__/testRuntime.spec.ts +++ b/packages/runtime-test/__tests__/testRuntime.spec.ts @@ -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(`
1
`) }) + + 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(`
1, 2
`) + }) + + 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() + }) })