-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add unit test for formatErrorMessage function
Signed-off-by: Sumu <[email protected]>
- Loading branch information
1 parent
d51b314
commit 1681a4d
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |