Skip to content

Commit

Permalink
WIP1-4p
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Sep 10, 2024
1 parent 539937f commit ef97226
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions commitlint/fpHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export class OptionStatic {
export class TypeHelpers {
// because instanceof doesn't work with primitive types (e.g. String), taken from https://stackoverflow.com/a/58184883/544947
public static IsInstanceOf(variable: any, type: any) {
if (variable === null || variable === undefined) {
throw new Error(
"Invalid 'variable' parameter passed in: null or undefined"
);
}
let res: boolean = false;
if (typeof type == "string") {
res = typeof variable == type.toLowerCase();
Expand Down
23 changes: 23 additions & 0 deletions commitlint/tests/testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ test("testing TypeHelpers.IsInstanceOf", () => {
expect(TypeHelpers.IsInstanceOf(bar, Foo)).toBe(false);
});

test("testing TypeHelpers.IsInstanceOf exceptions", () => {
let strNull = null;
expect(() => TypeHelpers.IsInstanceOf(strNull, String)).toThrowError(
"Invalid"
);
expect(() => TypeHelpers.IsInstanceOf(strNull, String)).toThrowError(
"parameter"
);
expect(() => TypeHelpers.IsInstanceOf(strNull, String)).toThrowError(
"null"
);
let strUndefined = undefined;
expect(() => TypeHelpers.IsInstanceOf(strUndefined, String)).toThrowError(
"Invalid"
);
expect(() => TypeHelpers.IsInstanceOf(strUndefined, String)).toThrowError(
"parameter"
);
expect(() => TypeHelpers.IsInstanceOf(strUndefined, String)).toThrowError(
"undefined"
);
});

export function runCommitLintOnMsg(inputMsg: string) {
// FIXME: should we .lowerCase().startsWith("win") in case it starts
// returning Win64 in the future? thing is, our CI doesn't like this
Expand Down

0 comments on commit ef97226

Please sign in to comment.