Commit | Line | Data |
---|---|---|
d05b53c7 JB |
1 | import { describe, it } from 'node:test' |
2 | ||
3 | import { expect } from 'expect' | |
4 | ||
b49550e2 JB |
5 | import { FileType } from '../../src/types/index.js' |
6 | import { handleFileException, setDefaultErrorParams } from '../../src/utils/ErrorUtils.js' | |
d05b53c7 JB |
7 | |
8 | await describe('ErrorUtils test suite', async () => { | |
b49550e2 JB |
9 | await it('Verify handleFileException()', () => { |
10 | const error = new Error() | |
11 | error.code = 'ENOENT' | |
12 | expect(() => { | |
0acbf5e6 | 13 | handleFileException('path/to/module.js', FileType.Authorization, error, 'log prefix |', {}) |
b49550e2 JB |
14 | }).toThrow(error) |
15 | expect(() => { | |
0acbf5e6 | 16 | handleFileException('path/to/module.js', FileType.Authorization, error, 'log prefix |', { |
b49550e2 JB |
17 | throwError: false |
18 | }) | |
19 | }).not.toThrow() | |
20 | }) | |
21 | ||
d05b53c7 JB |
22 | await it('Verify setDefaultErrorParams()', () => { |
23 | expect(setDefaultErrorParams({})).toStrictEqual({ throwError: true, consoleOut: false }) | |
24 | expect(setDefaultErrorParams({ throwError: false })).toStrictEqual({ | |
25 | throwError: false, | |
26 | consoleOut: false | |
27 | }) | |
28 | expect(setDefaultErrorParams({ throwError: false, consoleOut: true })).toStrictEqual({ | |
29 | throwError: false, | |
30 | consoleOut: true | |
31 | }) | |
32 | expect(setDefaultErrorParams({ throwError: true, consoleOut: true })).toStrictEqual({ | |
33 | throwError: true, | |
34 | consoleOut: true | |
35 | }) | |
36 | expect(setDefaultErrorParams({}, { throwError: false, consoleOut: false })).toStrictEqual({ | |
37 | throwError: false, | |
38 | consoleOut: false | |
39 | }) | |
40 | }) | |
41 | }) |