Skip to content

Commit

Permalink
test: add test case for proper effect teardown w/ withAsyncContext
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 6, 2021
1 parent 6fad209 commit d12206d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/runtime-core/__tests__/apiSetupHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
render,
serializeInner,
SetupContext,
Suspense
Suspense,
computed,
ComputedRef
} from '@vue/runtime-test'
import {
defineEmits,
Expand Down Expand Up @@ -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)
})
})
})

0 comments on commit d12206d

Please sign in to comment.