diff --git a/src/components/ErrorBoundary/PdapErrorBoundary.vue b/src/components/ErrorBoundary/PdapErrorBoundary.vue new file mode 100644 index 0000000..f96cfe7 --- /dev/null +++ b/src/components/ErrorBoundary/PdapErrorBoundary.vue @@ -0,0 +1,38 @@ + + diff --git a/src/components/ErrorBoundary/__snapshots__/error-boundary.spec.ts.snap b/src/components/ErrorBoundary/__snapshots__/error-boundary.spec.ts.snap new file mode 100644 index 0000000..b90f116 --- /dev/null +++ b/src/components/ErrorBoundary/__snapshots__/error-boundary.spec.ts.snap @@ -0,0 +1,10 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`ErrorBoundary > renders error content with error 1`] = ` +
+

Oops, something went wrong!

+

If you keep seeing this message, please email contact@pdap.io for assistance.

+
+`; + +exports[`ErrorBoundary > renders slot content with no error 1`] = `
`; diff --git a/src/components/ErrorBoundary/error-boundary.spec.ts b/src/components/ErrorBoundary/error-boundary.spec.ts new file mode 100644 index 0000000..562f106 --- /dev/null +++ b/src/components/ErrorBoundary/error-boundary.spec.ts @@ -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: '
', + }, + }); + }); + + 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(); + }); +});