Skip to content

Commit 1d5d188

Browse files
committed
Updated tests.
1 parent 9755409 commit 1d5d188

File tree

4 files changed

+225
-303
lines changed

4 files changed

+225
-303
lines changed

Diff for: tests/config.test.ts

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import {strict, strictEqual} from "assert";
2+
import VueLogger from "../src";
3+
import {LogLevels} from "../src/vue-logger/enum/log-levels";
4+
5+
describe("isValidOptions()", () => {
6+
7+
const logLevels = Object.keys(LogLevels).map((l) => l.toLowerCase());
8+
9+
test("isValidOptions() should pass with correct options.", () => {
10+
const input = VueLogger.isValidOptions({
11+
isEnabled: true,
12+
logLevel: "debug",
13+
stringifyArguments: false,
14+
showLogLevel: false,
15+
showMethodName: true,
16+
separator: "|",
17+
showConsoleColors: false,
18+
} as any, logLevels);
19+
strictEqual(input, true);
20+
});
21+
22+
test("isValidOptions() should fail with incorrect options.", () => {
23+
24+
strictEqual(VueLogger.isValidOptions({
25+
isEnabled: true,
26+
logLevel: "debug",
27+
stringifyArguments: false,
28+
showLogLevel: false,
29+
showMethodName: true,
30+
separator: "|||||",
31+
showConsoleColors: false,
32+
} as any, logLevels), false);
33+
34+
strictEqual(VueLogger.isValidOptions({
35+
isEnabled: true,
36+
logLevel: "debug",
37+
stringifyArguments: false,
38+
showLogLevel: false,
39+
showMethodName: true,
40+
separator: "|",
41+
showConsoleColors: "FOO",
42+
} as any, logLevels), false);
43+
44+
strictEqual(VueLogger.isValidOptions({
45+
isEnabled: true,
46+
logLevel: "debug",
47+
stringifyArguments: false,
48+
showLogLevel: false,
49+
showMethodName: "TEST",
50+
separator: "|",
51+
showConsoleColors: false,
52+
} as any, logLevels), false);
53+
54+
strictEqual(VueLogger.isValidOptions({
55+
isEnabled: true,
56+
logLevel: "debug",
57+
stringifyArguments: "TEST",
58+
showLogLevel: false,
59+
showMethodName: false,
60+
separator: "|",
61+
showConsoleColors: false,
62+
} as any, logLevels), false);
63+
64+
strictEqual(VueLogger.isValidOptions({
65+
isEnabled: true,
66+
logLevel: "debug",
67+
stringifyArguments: false,
68+
showLogLevel: "TEST",
69+
showMethodName: false,
70+
separator: "|",
71+
showConsoleColors: false,
72+
} as any, logLevels), false);
73+
74+
strictEqual(VueLogger.isValidOptions({
75+
isEnabled: true,
76+
logLevel: "TEST",
77+
stringifyArguments: false,
78+
showLogLevel: false,
79+
showMethodName: false,
80+
separator: "|",
81+
showConsoleColors: false,
82+
} as any, logLevels), false);
83+
84+
strictEqual(VueLogger.isValidOptions({
85+
logLevel: "debug",
86+
isEnabled: true,
87+
} as any, logLevels), true);
88+
89+
strictEqual(VueLogger.isValidOptions({
90+
isEnabled: "",
91+
logLevel: "debug",
92+
separator: "1234",
93+
} as any, logLevels), false);
94+
95+
strictEqual(VueLogger.isValidOptions({
96+
isEnabled: true,
97+
logLevel: "debug",
98+
stringifyArguments: false,
99+
showLogLevel: false,
100+
showMethodName: false,
101+
separator: "|",
102+
showConsoleColors: false,
103+
} as any, logLevels), true);
104+
105+
strictEqual(VueLogger.isValidOptions({
106+
isEnabled: false,
107+
logLevel: "debug",
108+
stringifyArguments: false,
109+
showLogLevel: false,
110+
showMethodName: false,
111+
separator: "|",
112+
showConsoleColors: false,
113+
} as any, logLevels), true);
114+
115+
strictEqual(VueLogger.isValidOptions({
116+
isEnabled: "",
117+
logLevel: "debug",
118+
stringifyArguments: false,
119+
showLogLevel: false,
120+
showMethodName: false,
121+
separator: "|",
122+
showConsoleColors: false,
123+
} as any, logLevels), false);
124+
125+
strictEqual(VueLogger.isValidOptions({
126+
isEnabled: null,
127+
logLevel: "debug",
128+
stringifyArguments: false,
129+
showLogLevel: false,
130+
showMethodName: false,
131+
separator: "|",
132+
showConsoleColors: false,
133+
} as any, logLevels), false);
134+
});
135+
});

Diff for: tests/install.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {notStrictEqual, strictEqual} from "assert";
2+
import chai from "chai";
3+
import Vue from "vue/dist/vue.min";
4+
import VueLogger from "../src";
5+
import {LogLevels} from "../src/vue-logger/enum/log-levels";
6+
import {ILoggerOptions} from "../src/vue-logger/interfaces/logger-options";
7+
const expect = chai.expect;
8+
9+
describe("vue-logger.ts", () => {
10+
11+
test("install() should work as expected with the correct params.", () => {
12+
const options: ILoggerOptions = {
13+
isEnabled: true,
14+
logLevel: LogLevels.FATAL,
15+
separator: "|",
16+
stringifyArguments: false,
17+
showConsoleColors: true,
18+
showLogLevel: false,
19+
showMethodName: false,
20+
};
21+
Vue.use(VueLogger, options);
22+
expect(Vue.$log).to.be.a("object");
23+
strictEqual(Vue.$log.debug("debug"), undefined);
24+
strictEqual(Vue.$log.info("info"), undefined);
25+
strictEqual(Vue.$log.warn("warn"), undefined);
26+
strictEqual(Vue.$log.error("error"), undefined);
27+
expect(Vue.$log.fatal("fatal")).to.exist;
28+
});
29+
30+
test("install() should throw an error with the an incorrect parameter.", () => {
31+
const options: any = {
32+
isEnabled: true,
33+
logLevel: LogLevels.DEBUG,
34+
separator: "|",
35+
stringifyArguments: false,
36+
showConsoleColors: true,
37+
showLogLevel: false,
38+
showMethodName: "wrong value for test.",
39+
};
40+
expect(() => {
41+
VueLogger.install(Vue, options);
42+
})
43+
.to
44+
.throw(Error, "Provided options for vuejs-logger are not valid.");
45+
});
46+
});

0 commit comments

Comments
 (0)