Skip to content

Commit 7f5dd11

Browse files
authored
test(nuxt): Add E2E test with NuxtErrorBoundary (#14754)
Adding a test to make sure error events bubble up when using `NuxtErrorBoundary`
1 parent 9e7b949 commit 7f5dd11

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<script setup>
22
import ErrorButton from '../components/ErrorButton.vue';
3+
4+
const catchErr = () => {
5+
console.log('Additional functionality in NuxtErrorBoundary');
6+
}
37
</script>
48

59
<template>
610
<ErrorButton id="errorBtn" error-text="Error thrown from Nuxt-3 E2E test app"/>
711
<ErrorButton id="errorBtn2" error-text="Another Error thrown from Nuxt-3 E2E test app"/>
8-
</template>
9-
10-
1112

13+
<NuxtErrorBoundary @error="catchErr">
14+
<ErrorButton id="error-in-error-boundary" error-text="Error thrown in Error Boundary"/>
15+
</NuxtErrorBoundary>
16+
</template>

dev-packages/e2e-tests/test-applications/nuxt-3/tests/errors.client.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,47 @@ test.describe('client-side errors', async () => {
2828
});
2929
});
3030

31+
test('captures error thrown in NuxtErrorBoundary', async ({ page }) => {
32+
const errorPromise = waitForError('nuxt-3', async errorEvent => {
33+
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown in Error Boundary';
34+
});
35+
36+
await page.goto(`/client-error`);
37+
await page.locator('#error-in-error-boundary').click();
38+
39+
const error = await errorPromise;
40+
41+
const expectedBreadcrumb = {
42+
category: 'console',
43+
message: 'Additional functionality in NuxtErrorBoundary',
44+
};
45+
46+
const matchingBreadcrumb = error.breadcrumbs.find(
47+
(breadcrumb: { category: string; message: string }) =>
48+
breadcrumb.category === expectedBreadcrumb.category && breadcrumb.message === expectedBreadcrumb.message,
49+
);
50+
51+
expect(matchingBreadcrumb).toBeTruthy();
52+
expect(matchingBreadcrumb?.category).toBe(expectedBreadcrumb.category);
53+
expect(matchingBreadcrumb?.message).toBe(expectedBreadcrumb.message);
54+
55+
expect(error.transaction).toEqual('/client-error');
56+
expect(error.sdk.name).toEqual('sentry.javascript.nuxt');
57+
expect(error).toMatchObject({
58+
exception: {
59+
values: [
60+
{
61+
type: 'Error',
62+
value: 'Error thrown in Error Boundary',
63+
mechanism: {
64+
handled: false,
65+
},
66+
},
67+
],
68+
},
69+
});
70+
});
71+
3172
test('shows parametrized route on button error', async ({ page }) => {
3273
const errorPromise = waitForError('nuxt-3', async errorEvent => {
3374
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Param Route Button';
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<script setup>
22
import ErrorButton from '../components/ErrorButton.vue';
3+
4+
const catchErr = () => {
5+
console.log('Additional functionality in NuxtErrorBoundary');
6+
}
37
</script>
48

59
<template>
610
<ErrorButton id="errorBtn" error-text="Error thrown from Nuxt-4 E2E test app"/>
711
<ErrorButton id="errorBtn2" error-text="Another Error thrown from Nuxt-4 E2E test app"/>
8-
</template>
9-
10-
1112

13+
<NuxtErrorBoundary @error="catchErr">
14+
<ErrorButton id="error-in-error-boundary" error-text="Error thrown in Error Boundary"/>
15+
</NuxtErrorBoundary>
16+
</template>

dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.client.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,47 @@ test.describe('client-side errors', async () => {
2828
});
2929
});
3030

31+
test('captures error thrown in NuxtErrorBoundary', async ({ page }) => {
32+
const errorPromise = waitForError('nuxt-4', async errorEvent => {
33+
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown in Error Boundary';
34+
});
35+
36+
await page.goto(`/client-error`);
37+
await page.locator('#error-in-error-boundary').click();
38+
39+
const error = await errorPromise;
40+
41+
const expectedBreadcrumb = {
42+
category: 'console',
43+
message: 'Additional functionality in NuxtErrorBoundary',
44+
};
45+
46+
const matchingBreadcrumb = error.breadcrumbs.find(
47+
(breadcrumb: { category: string; message: string }) =>
48+
breadcrumb.category === expectedBreadcrumb.category && breadcrumb.message === expectedBreadcrumb.message,
49+
);
50+
51+
expect(matchingBreadcrumb).toBeTruthy();
52+
expect(matchingBreadcrumb?.category).toBe(expectedBreadcrumb.category);
53+
expect(matchingBreadcrumb?.message).toBe(expectedBreadcrumb.message);
54+
55+
expect(error.transaction).toEqual('/client-error');
56+
expect(error.sdk.name).toEqual('sentry.javascript.nuxt');
57+
expect(error).toMatchObject({
58+
exception: {
59+
values: [
60+
{
61+
type: 'Error',
62+
value: 'Error thrown in Error Boundary',
63+
mechanism: {
64+
handled: false,
65+
},
66+
},
67+
],
68+
},
69+
});
70+
});
71+
3172
test('shows parametrized route on button error', async ({ page }) => {
3273
const errorPromise = waitForError('nuxt-4', async errorEvent => {
3374
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Param Route Button';

0 commit comments

Comments
 (0)