From e359bffb2c3662847ad41fc4a6a813253af00f32 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 20 Feb 2022 23:18:01 -0500 Subject: [PATCH] test: add stackTrace test and improve test descriptions --- packages/util/test/errors.spec.ts | 36 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/util/test/errors.spec.ts b/packages/util/test/errors.spec.ts index 4cc3d7a6aa..1a32692240 100644 --- a/packages/util/test/errors.spec.ts +++ b/packages/util/test/errors.spec.ts @@ -4,7 +4,7 @@ import { ErrorLogger } from '../src/errors' tape('ErrorLogger', (t) => { const errorLog = new ErrorLogger() - t.test('should assign the UNKNOWN_ERROR code to errors with undefined code', (st) => { + t.test('should assign the UNKNOWN_ERROR code to errors without code', (st) => { let error: any try { @@ -16,6 +16,18 @@ tape('ErrorLogger', (t) => { st.equal(error.code, ErrorLogger.errors.UNKNOWN_ERROR) st.end() }), + t.test('should preserve the stack trace of the throwError context', (st) => { + let error: any + + try { + errorLog.throwError() + } catch (e) { + error = e + } + + st.ok(/Error: {2}\| Details: code=UNKNOWN_ERROR\n {4}at Test./.test(error.stack)) + st.end() + }), t.test('should populate an error with UNKNOWN_ERROR code with all provided params', (st) => { let error: any @@ -28,26 +40,12 @@ tape('ErrorLogger', (t) => { error = e } + st.equal(error.code, ErrorLogger.errors.UNKNOWN_ERROR) st.equal(error.errorInfo1, 'Information on the error') st.equal(error.errorInfo2, 'More information on the error') st.end() - }) - t.test('should populate an error with UNKNOWN_ERROR code with all provided params', (st) => { - let error: any - - try { - errorLog.throwError(ErrorLogger.errors.UNKNOWN_ERROR, { - errorInfo1: 'Information on the error', - errorInfo2: 'More information on the error', - }) - } catch (e) { - error = e - } - - st.equal(error.code, ErrorLogger.errors.UNKNOWN_ERROR) - st.end() - }), - t.test('should add all error params to error message details', (st) => { + }), + t.test('should add all error params of UNKNOWN_ERROR to error message details', (st) => { let error: any try { @@ -65,7 +63,7 @@ tape('ErrorLogger', (t) => { ) st.end() }), - t.test('should append all error params to existing error message', (st) => { + t.test('should append all error details to provided error message', (st) => { let error: any try {