Skip to content

Commit d12206d

Browse files
committed
test: add test case for proper effect teardown w/ withAsyncContext
1 parent 6fad209 commit d12206d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

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

+33-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
render,
1010
serializeInner,
1111
SetupContext,
12-
Suspense
12+
Suspense,
13+
computed,
14+
ComputedRef
1315
} from '@vue/runtime-test'
1416
import {
1517
defineEmits,
@@ -253,5 +255,35 @@ describe('SFC <script setup> helpers', () => {
253255
await ready
254256
expect(getCurrentInstance()).toBeNull()
255257
})
258+
259+
test('should teardown in-scope effects', async () => {
260+
let resolve: (val?: any) => void
261+
const ready = new Promise(r => {
262+
resolve = r
263+
})
264+
265+
let c: ComputedRef
266+
267+
const Comp = defineComponent({
268+
async setup() {
269+
await withAsyncContext(Promise.resolve())
270+
271+
c = computed(() => {})
272+
// register the lifecycle after an await statement
273+
onMounted(resolve)
274+
return () => ''
275+
}
276+
})
277+
278+
const app = createApp(() => h(Suspense, () => h(Comp)))
279+
const root = nodeOps.createElement('div')
280+
app.mount(root)
281+
282+
await ready
283+
expect(c!.effect.active).toBe(true)
284+
285+
app.unmount()
286+
expect(c!.effect.active).toBe(false)
287+
})
256288
})
257289
})

0 commit comments

Comments
 (0)