-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d03573c
commit e0e4e49
Showing
6 changed files
with
98 additions
and
51 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
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
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
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 |
---|---|---|
@@ -1,12 +1,55 @@ | ||
import { getErrorContext } from "./ErrorContext"; | ||
import { handleTezError } from "./estimate"; | ||
|
||
jest.mock("./estimate", () => ({ | ||
handleTezError: jest.fn(), | ||
})); | ||
|
||
describe("getErrorContext", () => { | ||
it("should get error context", () => { | ||
const { description, stacktrace } = getErrorContext({ | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should handle error object with message and stack", () => { | ||
jest.mocked(handleTezError).mockReturnValue(undefined); | ||
const error = { | ||
message: "some error message", | ||
stack: "some stacktrace", | ||
}); | ||
expect(description).toEqual("some error message"); | ||
expect(stacktrace).toEqual("some stacktrace"); | ||
}; | ||
|
||
const context = getErrorContext(error); | ||
|
||
expect(context.technicalDetails).toBe("some error message"); | ||
expect(context.stacktrace).toBe("some stacktrace"); | ||
expect(context.description).toBe( | ||
"Something went wrong. Please try again or contact support if the issue persists." | ||
); | ||
expect(context.timestamp).toBeDefined(); | ||
}); | ||
|
||
it("should handle string errors", () => { | ||
jest.mocked(handleTezError).mockReturnValue(undefined); | ||
const error = "string error message"; | ||
|
||
const context = getErrorContext(error); | ||
|
||
expect(context.technicalDetails).toBe("string error message"); | ||
expect(context.stacktrace).toBe(""); | ||
expect(context.description).toBe( | ||
"Something went wrong. Please try again or contact support if the issue persists." | ||
); | ||
expect(context.timestamp).toBeDefined(); | ||
}); | ||
|
||
it("should handle Error instances with Tezos-specific errors", () => { | ||
jest.mocked(handleTezError).mockReturnValue("Handled tez error message"); | ||
const error = new Error("test error"); | ||
|
||
const context = getErrorContext(error); | ||
|
||
expect(context.technicalDetails).toBe("test error"); | ||
expect(context.description).toBe("Handled tez error message"); | ||
expect(context.stacktrace).toBeDefined(); | ||
expect(context.timestamp).toBeDefined(); | ||
}); | ||
}); |
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
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