Skip to content

Commit 5a28b32

Browse files
test(logger): added unit test for URIError (#451)
* test(logger): added unit test for URIError * chore(npm): Revert name addition
1 parent 671bf00 commit 5a28b32

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: packages/logger/tests/unit/formatter/PowertoolLogFormatter.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,34 @@ describe('Class: PowertoolLogFormatter', () => {
272272
expect(shouldThrow).toThrowError(expect.any(TypeError));
273273
});
274274

275+
test('When an error of type URIError is passed, it returns an object with expected structure and values', () => {
276+
277+
// Prepare
278+
const formatter = new PowertoolLogFormatter();
279+
const shouldThrow = (): void => {
280+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
281+
// @ts-ignore
282+
decodeURIComponent('%');
283+
};
284+
285+
// Act
286+
try {
287+
shouldThrow();
288+
} catch (error) {
289+
// Assess
290+
expect(error).toBeInstanceOf(URIError);
291+
const formattedURIError = formatter.formatError(<URIError>error);
292+
expect(formattedURIError).toEqual({
293+
location: expect.stringMatching(/PowertoolLogFormatter.test.ts:[0-9]+/),
294+
message: 'URI malformed',
295+
name: 'URIError',
296+
stack: expect.stringMatching(/PowertoolLogFormatter.test.ts:[0-9]+:[0-9]+/),
297+
});
298+
}
299+
300+
expect(shouldThrow).toThrowError(expect.any(URIError));
301+
});
302+
275303
});
276304

277305
describe('Method: formatTimestamp', () => {

0 commit comments

Comments
 (0)