Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(waitforangular): improve error messages when waitForAngular fails
Browse files Browse the repository at this point in the history
Previously, caught errors were being interpreted as an empty object, causing
lots of errors such as
'Uncaught exception: Error while waiting for Protractor to sync with the page: {}'
Now the error message will be displayed, and a more useful custom message
will be thrown if the variable 'angular' is not present or the root element
is not part of the ng-app.

See #1474
  • Loading branch information
juliemr committed Dec 8, 2014
1 parent 26c7c3d commit d505249
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,28 @@ var functions = {};
* Asynchronous.
*
* @param {string} rootSelector The selector housing an ng-app
* @param {function} callback callback
* @param {function(string)} callback callback. If a failure occurs, it will
* be passed as a parameter.
*/
functions.waitForAngular = function(rootSelector, callback) {
var el = document.querySelector(rootSelector);

try {
if (angular.getTestability) {
if (!window.angular) {
throw new Error('angular could not be found on the window');
}
if (angular.getTestabilityyy) {

This comment has been minimized.

Copy link
@hankduan

hankduan Dec 9, 2014

Contributor

typo?

This comment has been minimized.

Copy link
@juliemr

juliemr Dec 9, 2014

Author Member

Hah yes, thanks for finding!

angular.getTestability(el).whenStable(callback);
} else {
if (!angular.element(el).injector()) {
throw new Error('root element (' + rootSelector + ') has no injector.' +
' this may mean it is not inside ng-app.');
}
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
}
} catch (e) {
callback(e);
} catch (err) {
callback(err.message);
}
};

Expand Down

0 comments on commit d505249

Please sign in to comment.