Skip to content

Commit c837301

Browse files
committed
updated test to check the details of the error
1 parent 5ee4241 commit c837301

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/event-handler/tests/unit/rest/Router/error-handling.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ describe('Class: Router - Error Handling', () => {
542542

543543
it('handles throwing a generic error from the error handler', async () => {
544544
// Prepare
545+
vi.stubEnv('POWERTOOLS_DEV', 'true');
545546
const app = new Router();
546547

547548
app.errorHandler(BadRequestError, async () => {
@@ -556,15 +557,13 @@ describe('Class: Router - Error Handling', () => {
556557
const result = await app.resolve(createTestEvent('/test', 'GET'), context);
557558

558559
// Assess
559-
expect(result).toEqual({
560-
statusCode: HttpErrorCodes.INTERNAL_SERVER_ERROR,
561-
body: JSON.stringify({
562-
statusCode: HttpErrorCodes.INTERNAL_SERVER_ERROR,
563-
error: 'Internal Server Error',
564-
message: 'Internal Server Error',
565-
}),
566-
headers: { 'content-type': 'application/json' },
567-
isBase64Encoded: false,
560+
expect(result.statusCode).toBe(HttpErrorCodes.INTERNAL_SERVER_ERROR);
561+
const body = JSON.parse(result.body);
562+
expect(body.error).toBe('Internal Server Error');
563+
expect(body.message).toBe('This error is thrown from the error handler');
564+
expect(body.stack).toBeDefined();
565+
expect(body.details).toEqual({
566+
errorName: 'Error',
568567
});
569568
});
570569
});

0 commit comments

Comments
 (0)