From e485026a6bb1506eeeb13addf24c7d6310f93b08 Mon Sep 17 00:00:00 2001 From: Ruslan Hrabovyi Date: Mon, 11 Mar 2024 23:36:03 +0100 Subject: [PATCH 1/2] preserve original error instance ...under the `cause.error` --- addon/src/-private/better-errors.js | 3 ++- .../tests/unit/-private/properties/visitable-test.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/addon/src/-private/better-errors.js b/addon/src/-private/better-errors.js index 52d36e98..4ba079dd 100644 --- a/addon/src/-private/better-errors.js +++ b/addon/src/-private/better-errors.js @@ -24,7 +24,8 @@ export function throwBetterError(node, key, error, { selector } = {}) { const wrapperError = new PageObjectError(message, { cause: { - message: error.cause ? error.cause.toString() : message, + message, + error: error.cause, key, node, selector, diff --git a/test-app/tests/unit/-private/properties/visitable-test.ts b/test-app/tests/unit/-private/properties/visitable-test.ts index 571ad6a7..74c6b84c 100644 --- a/test-app/tests/unit/-private/properties/visitable-test.ts +++ b/test-app/tests/unit/-private/properties/visitable-test.ts @@ -114,10 +114,15 @@ PageObject: 'page.foo("[object Object]")' Selector: '.scope'` ); - assert.strictEqual( - (e as any).cause.message, - 'UnrecognizedURLError: /non-existing-url/value' + const originalError = (e as any).cause.error; + assert.true( + originalError instanceof Error, + '`cause.error` is an instance of `Error`' ); + + assert.strictEqual(originalError.name, 'UnrecognizedURLError'); + + assert.strictEqual(originalError.message, '/non-existing-url/value'); } }); }); From 9e0ca4924647cc19781d84d398fef3b2a927fb97 Mon Sep 17 00:00:00 2001 From: Ruslan Hrabovyi Date: Mon, 11 Mar 2024 23:36:50 +0100 Subject: [PATCH 2/2] doc: add a brief note about the `cause.error` in the `visitable` error instance --- addon/src/properties/visitable.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addon/src/properties/visitable.js b/addon/src/properties/visitable.js index 64c85c98..e38f9000 100644 --- a/addon/src/properties/visitable.js +++ b/addon/src/properties/visitable.js @@ -127,7 +127,9 @@ function appendQueryParams(path, queryParams) { * @param {string} path - Full path of the route to visit * @return {Descriptor} * - * @throws Will throw an error if dynamic segments are not filled + * @throws Will throw an error if dynamic segments are not filled. + * Note: An error instance may contain a `cause.error` property + * with the original error thrown by an underlying test helper. */ export function visitable(path) { return action(function (dynamicSegmentsAndQueryParams = {}) {