Skip to content

Commit

Permalink
throwBetterError logs error to console
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Andresian committed May 3, 2017
1 parent 4ce4092 commit 579e9d8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/-private/better-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export function throwBetterError(node, key, msg, { selector } = {}) {
fullErrorMessage = `${fullErrorMessage}\n Selector: '${selector}'`;
}

Ember.Logger.error(fullErrorMessage);
throw new Ember.Error(fullErrorMessage);
}
60 changes: 60 additions & 0 deletions tests/unit/-private/better-errors-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Ember from 'ember';
import { test, module } from 'qunit';
import { create } from 'ember-cli-page-object';
import {
throwBetterError
} from 'ember-cli-page-object/-private/better-errors';

const page = create({
foo: {
scope: '.foo',
bar: {
scope: '.bar',
focus() {}
}
}
});

module('Unit | throwBetterError');

test('shows the expected error message when `selector` is not passed in', function(assert) {
assert.expect(1);

const fn = () => {
throwBetterError(page.foo.bar, 'focus', 'Oops!');
};
const expectedError = new Ember.Error(
"Oops!\n\nPageObject: 'page.foo.bar.focus'"
);

assert.throws(fn, expectedError, 'should show message & property path');
});

test('shows the expected error message when `selector` is passed in', function(assert) {
assert.expect(1);

const fn = () => {
throwBetterError(page.foo.bar, 'focus', 'Oops!', { selector: '.foo .bar' });
};
const expectedError = new Ember.Error(
"Oops!\n\nPageObject: 'page.foo.bar.focus'\n Selector: '.foo .bar'"
);

assert.throws(fn, expectedError, 'should show message, property path, & selector');
});

test('logs the error to the console', function(assert) {
assert.expect(2);

const origEmberLoggerError = Ember.Logger.error;

try {
Ember.Logger.error = (msg) => {
assert.equal(msg, "Oops!\n\nPageObject: 'page.foo.bar.focus'");
};

assert.throws(() => throwBetterError(page.foo.bar, 'focus', 'Oops!'));
} finally {
Ember.Logger.error = origEmberLoggerError;
}
});

0 comments on commit 579e9d8

Please sign in to comment.