Skip to content

Commit 3d19ecc

Browse files
committed
test(error): update test cases
1 parent 1fdab3c commit 3d19ecc

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/error.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "ts-jest";
2-
import { IErrorObject, ILogObject, Logger } from "../src";
2+
import { IErrorObject, ILogObject, Logger, LoggerWithoutCallSite } from "../src";
33
import { doesLogContain } from "./helper";
44

55
let stdOut: string[] = [];
@@ -20,6 +20,7 @@ const loggerConfig = {
2020

2121
const loggerPretty: Logger = new Logger({ ...loggerConfig, type: "pretty" });
2222
const loggerJson: Logger = new Logger({ ...loggerConfig, type: "json" });
23+
const loggerJsonWithoutCallsite: Logger = new LoggerWithoutCallSite({ ...loggerConfig, type: "json" });
2324

2425
class TestError extends Error {
2526
constructor(message: string) {
@@ -65,6 +66,23 @@ describe("Logger: Error with details", () => {
6566
}
6667
});
6768

69+
test("JSON: Check if logger works without callsite wrapper", (): void => {
70+
try {
71+
let obj: any;
72+
const id = obj.id; // generating uncaught exception
73+
} catch (err) {
74+
loggerJsonWithoutCallsite.error(err);
75+
const logObj: ILogObject = JSON.parse(stdErr[0]);
76+
const errorObj: IErrorObject = logObj.argumentsArray?.[0] as IErrorObject;
77+
78+
expect(errorObj?.message).toContain(
79+
"Cannot read property 'id' of undefined"
80+
);
81+
82+
expect(errorObj?.stack?.[0].fileName).toContain("error.test.ts");
83+
}
84+
});
85+
6886
test("Helper: Print error", (): void => {
6987
const error = new TestError("TestError");
7088
const errorObject = loggerJson.prettyError(error, true);

0 commit comments

Comments
 (0)