mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 09:51:01 -05:00
Made a helper method to check if an object is an error
This commit is contained in:
parent
5892ef60d8
commit
3fe2a3fdc9
2 changed files with 21 additions and 0 deletions
10
src/utils/errors/error.ts
Normal file
10
src/utils/errors/error.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Determines if the input is an {@link Error}.
|
||||||
|
*
|
||||||
|
* @param error - Input to be checked.
|
||||||
|
*
|
||||||
|
* @returns `true` if the input is an `Error`; otherwise, `false`.
|
||||||
|
*/
|
||||||
|
export function isError(error: unknown): error is Error {
|
||||||
|
return error instanceof Error;
|
||||||
|
}
|
11
tests/unit/utils/errors.ts/error.spec.ts
Normal file
11
tests/unit/utils/errors.ts/error.spec.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { isError } from "@/utils/errors/error";
|
||||||
|
|
||||||
|
describe("isError", () => {
|
||||||
|
test("returns true if the input is an instance of Error", () => {
|
||||||
|
expect(isError(new Error("test error"))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns false if the input is not an instance of Error", () => {
|
||||||
|
expect(isError("not an error")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue