test: add test case for proper effect teardown w/ withAsyncContext
This commit is contained in:
parent
6fad2093a4
commit
d12206db8e
@ -9,7 +9,9 @@ import {
|
||||
render,
|
||||
serializeInner,
|
||||
SetupContext,
|
||||
Suspense
|
||||
Suspense,
|
||||
computed,
|
||||
ComputedRef
|
||||
} from '@vue/runtime-test'
|
||||
import {
|
||||
defineEmits,
|
||||
@ -253,5 +255,35 @@ describe('SFC <script setup> helpers', () => {
|
||||
await ready
|
||||
expect(getCurrentInstance()).toBeNull()
|
||||
})
|
||||
|
||||
test('should teardown in-scope effects', async () => {
|
||||
let resolve: (val?: any) => void
|
||||
const ready = new Promise(r => {
|
||||
resolve = r
|
||||
})
|
||||
|
||||
let c: ComputedRef
|
||||
|
||||
const Comp = defineComponent({
|
||||
async setup() {
|
||||
await withAsyncContext(Promise.resolve())
|
||||
|
||||
c = computed(() => {})
|
||||
// register the lifecycle after an await statement
|
||||
onMounted(resolve)
|
||||
return () => ''
|
||||
}
|
||||
})
|
||||
|
||||
const app = createApp(() => h(Suspense, () => h(Comp)))
|
||||
const root = nodeOps.createElement('div')
|
||||
app.mount(root)
|
||||
|
||||
await ready
|
||||
expect(c!.effect.active).toBe(true)
|
||||
|
||||
app.unmount()
|
||||
expect(c!.effect.active).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user