|
| 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 | +}); |
0 commit comments