Skip to content

Commit

Permalink
Merge pull request #1 from ro0gr/preserve-orig-error-instance
Browse files Browse the repository at this point in the history
Preserve original error instance
  • Loading branch information
simonihmig authored Mar 13, 2024
2 parents 5754361 + 9e0ca49 commit 72aa2d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion addon/src/-private/better-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion addon/src/properties/visitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
11 changes: 8 additions & 3 deletions test-app/tests/unit/-private/properties/visitable-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});

0 comments on commit 72aa2d8

Please sign in to comment.