-
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.
chore: update beta with main [no ci] (#75)
- Loading branch information
1 parent
9ab2dd7
commit 7c9011f
Showing
3 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<component | ||
:is="component" | ||
v-if="error" | ||
class="pdap-flex-container-center h-[full]" | ||
> | ||
<h1>Oops, something went wrong!</h1> | ||
<p class="max-w-full" data-test="error-boundary-message"> | ||
If you keep seeing this message, please email | ||
<a href="mailto:contact@pdap.io">contact@pdap.io</a> for assistance. | ||
</p> | ||
</component> | ||
<slot v-else /> | ||
</template> | ||
<script> | ||
export default { | ||
props: { | ||
component: { | ||
type: String, | ||
default: 'div', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
error: false, | ||
}; | ||
}, | ||
/* TODO: figure out how to cover this lifecycle method in tests */ | ||
errorCaptured(error) { | ||
this.interceptError(error); | ||
}, | ||
methods: { | ||
interceptError(error) { | ||
this.error = error; | ||
}, | ||
}, | ||
}; | ||
</script> |
10 changes: 10 additions & 0 deletions
10
src/components/ErrorBoundary/__snapshots__/error-boundary.spec.ts.snap
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,10 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`ErrorBoundary > renders error content with error 1`] = ` | ||
<div class="pdap-flex-container-center h-[full]"> | ||
<h1>Oops, something went wrong!</h1> | ||
<p class="max-w-full"> If you keep seeing this message, please email <a href="mailto:contact@pdap.io">contact@pdap.io</a> for assistance. </p> | ||
</div> | ||
`; | ||
|
||
exports[`ErrorBoundary > renders slot content with no error 1`] = `<div></div>`; |
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,31 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
import ErrorBoundary from './PdapErrorBoundary.vue'; | ||
import { nextTick } from 'vue'; | ||
|
||
let wrapper; | ||
|
||
describe('ErrorBoundary', () => { | ||
beforeEach(() => { | ||
wrapper = mount(ErrorBoundary, { | ||
slots: { | ||
default: '<div data-test="default-slot" />', | ||
}, | ||
}); | ||
}); | ||
|
||
it('renders slot content with no error', () => { | ||
expect(wrapper.find('[data-test="default-slot"]').exists()).toBe(true); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders error content with error', async () => { | ||
wrapper.vm.interceptError(new Error('Generic error')); | ||
await nextTick(); | ||
|
||
expect(wrapper.find('[data-test="error-boundary-message"]').exists()).toBe( | ||
true | ||
); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
}); |