diff --git a/packages/logger/tests/unit/formatter/PowertoolLogFormatter.test.ts b/packages/logger/tests/unit/formatter/PowertoolLogFormatter.test.ts index 0f7ae288e3..6e82fd41de 100644 --- a/packages/logger/tests/unit/formatter/PowertoolLogFormatter.test.ts +++ b/packages/logger/tests/unit/formatter/PowertoolLogFormatter.test.ts @@ -266,6 +266,34 @@ describe('Class: PowertoolLogFormatter', () => { expect(shouldThrow).toThrowError(expect.any(TypeError)); }); + test('When an error of type URIError is passed, it returns an object with expected structure and values', () => { + + // Prepare + const formatter = new PowertoolLogFormatter(); + const shouldThrow = (): void => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + decodeURIComponent('%'); + }; + + // Act + try { + shouldThrow(); + } catch (error) { + // Assess + expect(error).toBeInstanceOf(URIError); + const formattedURIError = formatter.formatError(error); + expect(formattedURIError).toEqual({ + location: expect.stringMatching(/PowertoolLogFormatter.test.ts:[0-9]+/), + message: 'URI malformed', + name: 'URIError', + stack: expect.stringMatching(/PowertoolLogFormatter.test.ts:[0-9]+:[0-9]+/), + }); + } + + expect(shouldThrow).toThrowError(expect.any(URIError)); + }); + }); describe('Method: formatTimestamp', () => {