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

test(nuxt): Add E2E test with NuxtErrorBoundary #14754

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<script setup>
import ErrorButton from '../components/ErrorButton.vue';

const catchErr = () => {
console.log('Additional functionality in NuxtErrorBoundary');
}
</script>

<template>
<ErrorButton id="errorBtn" error-text="Error thrown from Nuxt-3 E2E test app"/>
<ErrorButton id="errorBtn2" error-text="Another Error thrown from Nuxt-3 E2E test app"/>
</template>



<NuxtErrorBoundary @error="catchErr">
<ErrorButton id="error-in-error-boundary" error-text="Error thrown in Error Boundary"/>
</NuxtErrorBoundary>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,47 @@ test.describe('client-side errors', async () => {
});
});

test('captures error thrown in NuxtErrorBoundary', async ({ page }) => {
const errorPromise = waitForError('nuxt-3', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown in Error Boundary';
});

await page.goto(`/client-error`);
await page.locator('#error-in-error-boundary').click();

const error = await errorPromise;

const expectedBreadcrumb = {
category: 'console',
message: 'Additional functionality in NuxtErrorBoundary',
};

const matchingBreadcrumb = error.breadcrumbs.find(
(breadcrumb: { category: string; message: string }) =>
breadcrumb.category === expectedBreadcrumb.category && breadcrumb.message === expectedBreadcrumb.message,
);

expect(matchingBreadcrumb).toBeTruthy();
expect(matchingBreadcrumb?.category).toBe(expectedBreadcrumb.category);
expect(matchingBreadcrumb?.message).toBe(expectedBreadcrumb.message);

expect(error.transaction).toEqual('/client-error');
expect(error.sdk.name).toEqual('sentry.javascript.nuxt');
expect(error).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Error thrown in Error Boundary',
mechanism: {
handled: false,
},
},
],
},
});
});

test('shows parametrized route on button error', async ({ page }) => {
const errorPromise = waitForError('nuxt-3', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Param Route Button';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<script setup>
import ErrorButton from '../components/ErrorButton.vue';

const catchErr = () => {
console.log('Additional functionality in NuxtErrorBoundary');
}
</script>

<template>
<ErrorButton id="errorBtn" error-text="Error thrown from Nuxt-4 E2E test app"/>
<ErrorButton id="errorBtn2" error-text="Another Error thrown from Nuxt-4 E2E test app"/>
</template>



<NuxtErrorBoundary @error="catchErr">
<ErrorButton id="error-in-error-boundary" error-text="Error thrown in Error Boundary"/>
</NuxtErrorBoundary>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,47 @@ test.describe('client-side errors', async () => {
});
});

test('captures error thrown in NuxtErrorBoundary', async ({ page }) => {
const errorPromise = waitForError('nuxt-4', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown in Error Boundary';
});

await page.goto(`/client-error`);
await page.locator('#error-in-error-boundary').click();

const error = await errorPromise;

const expectedBreadcrumb = {
category: 'console',
message: 'Additional functionality in NuxtErrorBoundary',
};

const matchingBreadcrumb = error.breadcrumbs.find(
(breadcrumb: { category: string; message: string }) =>
breadcrumb.category === expectedBreadcrumb.category && breadcrumb.message === expectedBreadcrumb.message,
);

expect(matchingBreadcrumb).toBeTruthy();
expect(matchingBreadcrumb?.category).toBe(expectedBreadcrumb.category);
expect(matchingBreadcrumb?.message).toBe(expectedBreadcrumb.message);

expect(error.transaction).toEqual('/client-error');
expect(error.sdk.name).toEqual('sentry.javascript.nuxt');
expect(error).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Error thrown in Error Boundary',
mechanism: {
handled: false,
},
},
],
},
});
});

test('shows parametrized route on button error', async ({ page }) => {
const errorPromise = waitForError('nuxt-4', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Param Route Button';
Expand Down
Loading