All files / addon-test-support better-errors.js

18.18% Statements 2/11
0% Branches 0/3
0% Functions 0/1
18.18% Lines 2/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38        1x   1x                                                              
import Ember from 'ember';
import EmberError from '@ember/error';
import Ceibo from 'ceibo';
 
const { Logger } = Ember;
 
export const ELEMENT_NOT_FOUND = 'Element not found.';
 
/**
 * Throws an error with a descriptive message.
 *
 * @param {Ceibo} node              PageObject node containing the property that triggered the error
 * @param {string} key              Key of PageObject property tht triggered the error
 * @param {string} msg              Error message
 * @param {Object} options
 * @param {string} options.selector Selector of element targeted by PageObject property
 * @return {Ember.Error}
 */
export function throwBetterError(node, key, msg, { selector } = {}) {
  let path = [key];
  let current;
 
  for (current = node; current; current = Ceibo.parent(current)) {
    path.unshift(Ceibo.meta(current).key);
  }
 
  path[0] = 'page';
 
  let fullErrorMessage = `${msg}\n\nPageObject: '${path.join('.')}'`;
 
  if (selector) {
    fullErrorMessage = `${fullErrorMessage}\n  Selector: '${selector}'`;
  }
 
  Logger.error(fullErrorMessage);
  throw new EmberError(fullErrorMessage);
}