Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): return hook() in wrappedHook to handle the async call in KeepAliveHook. #4978

Merged
merged 3 commits into from
Nov 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(runtime-core): add test case.
  • Loading branch information
ygj6 committed Nov 20, 2021
commit cb1214700748004142978ee5a27660bb26b182ef
21 changes: 17 additions & 4 deletions packages/runtime-core/__tests__/errorHandling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
nextTick,
defineComponent,
watchEffect,
KeepAlive,
onActivated,
createApp
} from '@vue/runtime-test'

Expand Down Expand Up @@ -53,6 +55,7 @@ describe('error handling', () => {

test('propagation stoppage', () => {
ygj6 marked this conversation as resolved.
Show resolved Hide resolved
const err = new Error('foo')
const err2 = new Error('bar')
const fn = jest.fn()

const Comp = {
Expand All @@ -71,7 +74,7 @@ describe('error handling', () => {
fn(err, info, 'child')
return false
})
return () => h(GrandChild)
return () => h(KeepAlive, null, () => h(GrandChild))
}
}

Expand All @@ -80,17 +83,22 @@ describe('error handling', () => {
onMounted(() => {
throw err
})
onActivated(() => {
throw err2
})
return () => null
}
}

render(h(Comp), nodeOps.createElement('div'))
expect(fn).toHaveBeenCalledTimes(1)
expect(fn).toHaveBeenCalledTimes(2)
expect(fn).toHaveBeenCalledWith(err, 'mounted hook', 'child')
expect(fn).toHaveBeenCalledWith(err2, 'activated hook', 'child')
})

test('async error handling', async () => {
test.only('async error handling', async () => {
const err = new Error('foo')
const err2 = new Error('bar')
const fn = jest.fn()

const Comp = {
Expand All @@ -99,7 +107,7 @@ describe('error handling', () => {
fn(err, info)
return false
})
return () => h(Child)
return () => h(KeepAlive, null, () => h(Child))
}
}

Expand All @@ -108,14 +116,19 @@ describe('error handling', () => {
onMounted(async () => {
throw err
})
onActivated(async () => {
throw err2
})
},
render() {}
}

render(h(Comp), nodeOps.createElement('div'))
expect(fn).not.toHaveBeenCalled()
await new Promise(r => setTimeout(r))
expect(fn).toHaveBeenCalledTimes(2)
expect(fn).toHaveBeenCalledWith(err, 'mounted hook')
expect(fn).toHaveBeenCalledWith(err2, 'activated hook')
})

test('error thrown in onErrorCaptured', () => {
Expand Down