Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/logger/tests/unit/formatter/PowertoolLogFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<URIError>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', () => {
Expand Down