Skip to content

Commit

Permalink
Merge pull request #79 from fullstack-build/development
Browse files Browse the repository at this point in the history
Fix #78: Allow null and undefined parameters again
  • Loading branch information
terehov authored Jan 2, 2021
2 parents c8da472 + 1cd0dbc commit 20a9674
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 20a9674

Please sign in to comment.