Skip to content

Commit

Permalink
Fix #78: Allow null and undefined parameters again
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Jan 2, 2021
1 parent c8da472 commit 1cd0dbc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/LoggerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ export class LoggerHelper {
return value;
};

return LoggerHelper.cloneObjectRecursively(obj, maskValuesFn);
return obj != null
? LoggerHelper.cloneObjectRecursively(obj, maskValuesFn)
: obj;
}
}
57 changes: 57 additions & 0 deletions tests/parameter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import "ts-jest";
import { IStd, Logger } from "../src";
import { doesLogContain } from "./helper";
import exp = require("constants");

const stdOut: string[] = [];
const stdErr: string[] = [];

const logger: Logger = new Logger({
stdOut: {
write: (print: string) => {
stdOut.push(print);
},
},
stdErr: {
write: (print: string) => {
stdErr.push(print);
},
},
});

describe("Logger: Parameter", () => {
beforeEach(() => {
stdOut.length = 0;
stdErr.length = 0;
});

test("undefined", (): void => {
logger.silly(undefined);
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "undefined")).toBeTruthy();
});

test("null", (): void => {
logger.silly(null);
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "null")).toBeTruthy();
});

test("boolean", (): void => {
logger.silly(true);
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "true")).toBeTruthy();
});

test("number", (): void => {
logger.silly(0);
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "0")).toBeTruthy();
});

test("string", (): void => {
logger.silly("string");
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "string")).toBeTruthy();
});
});

0 comments on commit 1cd0dbc

Please sign in to comment.