-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
135 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script setup lang="ts"> | ||
import { useBoundary } from '@src'; | ||
const { reset, error } = useBoundary(); | ||
</script> | ||
|
||
<template> | ||
<p id="error_info">{{ error?.message ?? '' }}</p> | ||
<button id="reset_btn" @click="reset">reset</button> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default { | ||
name: 'HookTestComponent', | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { describe, test, beforeEach, expect } from 'vitest'; | ||
import HookTest from './components/hook.vue'; | ||
import ClickTest from './components/click.vue'; | ||
import { h, defineComponent } from 'vue'; | ||
import { mount } from '@vue/test-utils'; | ||
import ErrorBoundary from '@src'; | ||
|
||
let App: any; | ||
|
||
beforeEach(function () { | ||
App = defineComponent({ | ||
setup() { | ||
return function () { | ||
return h( | ||
ErrorBoundary, | ||
{}, | ||
{ | ||
default: () => h(ClickTest), | ||
fallback: () => h(HookTest), | ||
}, | ||
); | ||
}; | ||
}, | ||
}); | ||
}); | ||
|
||
describe('useBoundary hook', function () { | ||
test('error info', async function () { | ||
const app = mount(App); | ||
|
||
let throwBtn = app.get('#throw'); | ||
await throwBtn.trigger('click'); | ||
|
||
const error = app.find('#error_info'); | ||
expect(error.exists()).toBe(true); | ||
expect(error.text()).toBe('throwError'); | ||
|
||
const resetBtn = app.get('#reset_btn'); | ||
await resetBtn.trigger('click'); | ||
|
||
const throwBtn2 = app.find('#throw'); | ||
expect(throwBtn2.exists()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from '@hooks'; | ||
export { default } from './errorBoundary'; | ||
export type { | ||
ErrorBoundaryProps, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { warn, VEBOUNDARY_HOOK_KEY } from '@utils'; | ||
import { inject, Ref } from 'vue'; | ||
|
||
type BoundaryState = { | ||
error: Ref<Error | null>; | ||
reset: () => void; | ||
}; | ||
|
||
export function useBoundary() { | ||
const info = inject<BoundaryState>(VEBOUNDARY_HOOK_KEY); | ||
if (!info) warn('Please use useboundary in VeErrorBoundary'); | ||
return info as BoundaryState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './log'; | ||
export * from './key'; | ||
export * from './devtools'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const VEBOUNDARY_HOOK_KEY = Symbol('veboundary'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters