-
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.
♻️ Refactor(oh-my-error)!: Refactoring and adding mass of new feature…
…s to prepare package to version `2.0.0`
- Loading branch information
1 parent
cf02f35
commit dd36974
Showing
27 changed files
with
770 additions
and
218 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./myErrorCatcher"; | ||
export * from "./myErrorWrapper"; | ||
export * from "./myErrorHandler"; | ||
export * from "./myError"; |
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,59 @@ | ||
/* eslint-disable @EslintSonar/no-duplicate-string */ | ||
import { describe, it, expect } from "vitest"; | ||
import { myError } from "./myError"; | ||
import type { IMyError, TMyErrorList } from "@/types"; | ||
|
||
describe("[FUNCTION] myError", () => { | ||
it("should return a basic error object", () => { | ||
const errorObj: IMyError = { | ||
name: "Test Error", | ||
message: "This is a test error", | ||
code: 500 | ||
}; | ||
|
||
const result = myError(errorObj); | ||
expect(result).toEqual(errorObj); | ||
}); | ||
it("Example from Function should pass", () => { | ||
const MyErrorList = { | ||
BLACKLISTED: { | ||
name: "Black Listed Name", | ||
hint: "Try use other one!", | ||
message: (name: string) => `${name} is on black list!` | ||
} | ||
} as const satisfies TMyErrorList; | ||
|
||
expect(myError(MyErrorList.BLACKLISTED, { message: ["nameInputed"] })).toEqual({ | ||
...MyErrorList.BLACKLISTED, | ||
message: (() => MyErrorList.BLACKLISTED.message("nameInputed"))() | ||
}); | ||
}); | ||
it("should return solved test", () => { | ||
const errorObj = { | ||
name: "Black Listed Name", | ||
message: (name: string, idNumber: number) => `${name} with ${idNumber} is blacklisted!`, | ||
code: 500 | ||
} as const satisfies IMyError; | ||
|
||
const result = myError(errorObj, { message: ["BadName", 123] }); | ||
expect(result).toEqual({ ...errorObj, message: `BadName with 123 is blacklisted!` }); | ||
}); | ||
it("Should not overwrite current keys which are not functions", () => { | ||
const errorObj = { | ||
name: "Black Listed Name", | ||
message: (name: string, idNumber: number) => `${name} with ${idNumber} is blacklisted!`, | ||
code: 500 | ||
} as const satisfies IMyError; | ||
const result = myError(errorObj, { message: ["BadName", 123] }); | ||
expect(result).toEqual({ ...errorObj, message: `BadName with 123 is blacklisted!` }); | ||
}); | ||
it("Should not add new keys", () => { | ||
const errorObj = { | ||
name: "Black Listed Name", | ||
message: (name: string, idNumber: number) => `${name} with ${idNumber} is blacklisted!`, | ||
code: 500 | ||
} as const satisfies IMyError; | ||
const result = myError(errorObj, { message: ["BadName", 123], nonono: "lololo" }); | ||
expect(result).toEqual({ ...errorObj, message: `BadName with 123 is blacklisted!` }); | ||
}); | ||
}); |
Oops, something went wrong.