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/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 = {}) { 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'); } }); });