Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: san650/ember-cli-page-object
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.3
Choose a base ref
...
head repository: san650/ember-cli-page-object
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.3.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 13, 2024

  1. Better errors from visitable (#640)

    * Better errors from visitable
    
    This adds the actual error message from Ember's router to the (too generic) message from `visitable`. This is especially important when your test needs to know what kind of error was triggered. For example some tests might want to handle `TransitionAborted` errors differently, see emberjs/ember-test-helpers#332 (comment).
    
    * Pass original error message from visit as Error#cause
    
    * preserve original error instance
    
    ...under the `cause.error`
    
    * doc: add a brief note about the `cause.error`
    
    in the `visitable` error instance
    
    ---------
    
    Co-authored-by: Ruslan Hrabovyi <kudgo.test@gmail.com>
    simonihmig and ro0gr authored Mar 13, 2024
    Copy the full SHA
    ed51bb1 View commit details

Commits on Mar 16, 2024

  1. v2.3.0

    ro0gr committed Mar 16, 2024
    Copy the full SHA
    278bea0 View commit details
Showing with 21 additions and 5 deletions.
  1. +1 −1 addon/package.json
  2. +1 −0 addon/src/-private/better-errors.js
  3. +7 −3 addon/src/properties/visitable.js
  4. +11 −1 test-app/tests/unit/-private/properties/visitable-test.ts
  5. +1 −0 test-app/tsconfig.json
2 changes: 1 addition & 1 deletion addon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-page-object",
"version": "2.2.3",
"version": "2.3.0",
"description": "This ember-cli addon eases the construction of page objects on your acceptance and integration tests",
"keywords": [
"acceptance",
1 change: 1 addition & 0 deletions addon/src/-private/better-errors.js
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ export function throwBetterError(node, key, error, { selector } = {}) {
const wrapperError = new PageObjectError(message, {
cause: {
message,
error: error.cause,
key,
node,
selector,
10 changes: 7 additions & 3 deletions addon/src/properties/visitable.js
Original file line number Diff line number Diff line change
@@ -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 = {}) {
@@ -138,8 +140,10 @@ export function visitable(path) {

return getAdapter()
.visit(fullPath)
.catch(() => {
throw new Error(`Failed to visit URL '${fullPath}'`);
.catch((e) => {
throw new Error(`Failed to visit URL '${fullPath}': ${e.toString()}`, {
cause: e,
});
});
});
}
12 changes: 11 additions & 1 deletion test-app/tests/unit/-private/properties/visitable-test.ts
Original file line number Diff line number Diff line change
@@ -108,11 +108,21 @@ module('visitable', function (hooks) {
} catch (e) {
assert.strictEqual(
e?.toString(),
`Error: Failed to visit URL '/non-existing-url/value'
`Error: Failed to visit URL '/non-existing-url/value': UnrecognizedURLError: /non-existing-url/value
PageObject: 'page.foo("[object Object]")'
Selector: '.scope'`
);

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');
}
});
});
1 change: 1 addition & 0 deletions test-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"compilerOptions": {
"target": "es2022",
// The combination of `baseUrl` with `paths` allows Ember's classic package
// layout, which is not resolvable with the Node resolution algorithm, to
// work with TypeScript.