feat: watchPostEffect

This commit is contained in:
Evan You
2021-07-09 21:47:15 -04:00
parent 3b64508e3b
commit 42ace9577d
2 changed files with 39 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ import {
shallowRef,
Ref
} from '@vue/reactivity'
import { watchPostEffect } from '../src/apiWatch'
// reference: https://vue-composition-api-rfc.netlify.com/api.html#watch
@@ -363,6 +364,32 @@ describe('api: watch', () => {
expect(result).toBe(true)
})
it('watchPostEffect', async () => {
const count = ref(0)
let result
const assertion = jest.fn(count => {
result = serializeInner(root) === `${count}`
})
const Comp = {
setup() {
watchPostEffect(() => {
assertion(count.value)
})
return () => count.value
}
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
expect(assertion).toHaveBeenCalledTimes(1)
expect(result).toBe(true)
count.value++
await nextTick()
expect(assertion).toHaveBeenCalledTimes(2)
expect(result).toBe(true)
})
it('flush timing: sync', async () => {
const count = ref(0)
const count2 = ref(0)