test(frontend): add unit test coverage for extractErrorMessage#6321
test(frontend): add unit test coverage for extractErrorMessage#6321rbelavadi wants to merge 2 commits into
Conversation
Automated Reviewer SuggestionsBased on the
|
|
/request-review @xuang7 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6321 +/- ##
============================================
- Coverage 61.02% 61.00% -0.02%
Complexity 3375 3375
============================================
Files 1140 1140
Lines 44923 44923
Branches 4942 4942
============================================
- Hits 27413 27407 -6
- Misses 16001 16008 +7
+ Partials 1509 1508 -1
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds frontend unit test coverage for extractErrorMessage (frontend/src/app/common/util/error.ts), a shared UI utility that normalizes unknown error shapes into a user-facing string.
Changes:
- Added
frontend/src/app/common/util/error.spec.tswith 7 unit tests covering the currently documented branches (nativeError,{ error: string },{ error: { message } }, and several fallback inputs).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it("should return the nested message when error is an object with a message", () => { | ||
| const testError = { error: { message: "nested" } }; | ||
| const result = extractErrorMessage(testError); | ||
| expect(result).toBe(testError.error.message); | ||
| }); |
xuang7
left a comment
There was a problem hiding this comment.
LGTM overall. Please also add a { error: null } case. Worth a backendErr !== null guard in error.ts too so it falls back instead of throwing.
What changes were proposed in this PR?
Adds
error.spec.tsto coverextractErrorMessage, a previously untested pure utility function incommon/util/that normalizes errors of unknown shape into a display-safe string. Covers all four behavior branches: a nativeErrorinstance, an object with a stringerrorkey, an object with a nested{ error: { message } }shape, and fallback behavior for unrecognized shapes (null, number, empty object, malformed error key).No production code was changed.
Any related issues, documentation, discussions?
Closes #6254
How was this PR tested?
Added 7 new unit tests in error.spec.ts covering all branches described in the issue. Ran locally via
npx ng test --include='**/error.spec.ts'; all 7 pass.Was this PR authored or co-authored using generative AI tooling?
No.