forked from san650/ember-cli-page-object
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
throwBetterError logs error to console
- Loading branch information
Anna Andresian
committed
May 3, 2017
1 parent
4ce4092
commit 579e9d8
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |