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

Commit d505249

Browse files
committed
fix(waitforangular): improve error messages when waitForAngular fails
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
1 parent 26c7c3d commit d505249

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/clientsidescripts.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,28 @@ var functions = {};
2323
* Asynchronous.
2424
*
2525
* @param {string} rootSelector The selector housing an ng-app
26-
* @param {function} callback callback
26+
* @param {function(string)} callback callback. If a failure occurs, it will
27+
* be passed as a parameter.
2728
*/
2829
functions.waitForAngular = function(rootSelector, callback) {
2930
var el = document.querySelector(rootSelector);
31+
3032
try {
31-
if (angular.getTestability) {
33+
if (!window.angular) {
34+
throw new Error('angular could not be found on the window');
35+
}
36+
if (angular.getTestabilityyy) {
3237
angular.getTestability(el).whenStable(callback);
3338
} else {
39+
if (!angular.element(el).injector()) {
40+
throw new Error('root element (' + rootSelector + ') has no injector.' +
41+
' this may mean it is not inside ng-app.');
42+
}
3443
angular.element(el).injector().get('$browser').
3544
notifyWhenNoOutstandingRequests(callback);
3645
}
37-
} catch (e) {
38-
callback(e);
46+
} catch (err) {
47+
callback(err.message);
3948
}
4049
};
4150

0 commit comments

Comments
 (0)