Skip to content

Commit

Permalink
WIP: add unit test for formatErrorMessage function
Browse files Browse the repository at this point in the history
Signed-off-by: Sumu <[email protected]>
  • Loading branch information
sumupitchayan committed Jan 10, 2025
1 parent d51b314 commit 1681a4d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/aws-cdk/test/api/util/error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { formatErrorMessage } from '../../../lib/util/error';

describe('formatErrorMessage', () => {
test('should return the formatted message for a regular Error object', () => {
const error = new Error('Something went wrong');
const result = formatErrorMessage(error);
expect(result).toBe('Something went wrong');
});

test('should return the formatted message for an AggregateError', () => {
const error = {
errors: [
new Error('Inner error 1'),
new Error('Inner error 2'),
new Error('Inner error 3'),
],
};
const result = formatErrorMessage(error);
expect(result).toBe('AggregateError: Inner error 1\nInner error 2\nInner error 3');
});

test('should return "Unknown error" for null or undefined error', () => {
expect(formatErrorMessage(null)).toBe('Unknown error');
expect(formatErrorMessage(undefined)).toBe('Unknown error');
});
});

0 comments on commit 1681a4d

Please sign in to comment.