Skip to content
Permalink
Browse files

style(testability): throw a more informative error when getting testa…

…bility

The angular.getTestability method requires an element parameter to determine
which Angular application to use. Currently, if the element provided is
undefined or outside of an Angular app, the error message is 'cannot read
property get of undefined'. Improving to a more relevant error message.
  • Loading branch information
juliemr committed Dec 8, 2014
1 parent a097aa9 commit 63db09753ef6c46cc63e7c523ff41d9f959dfcdd
Showing with 15 additions and 1 deletion.
  1. +9 −0 docs/content/error/ng/test.ngdoc
  2. +6 −1 src/Angular.js
@@ -0,0 +1,9 @@
@ngdoc error
@name ng:test
@fullName Testability Not Found
@description

Angular's testability helper, getTestability, requires a root element to be
passed in. This helps differentiate between different Angular apps on the same
page. This error is thrown when no injector is found for root element. It is
often because the root element is outside of the ng-app.
@@ -1428,7 +1428,12 @@ function reloadWithDebugInfo() {
* @param {DOMElement} element DOM element which is the root of angular application.
*/
function getTestability(rootElement) {
return angular.element(rootElement).injector().get('$$testability');
var injector = angular.element(rootElement).injector();
if (!injector) {
throw ngMinErr('test',
'no injector found for element argument to getTestability');
}
return injector.get('$$testability');
}

var SNAKE_CASE_REGEXP = /[A-Z]/g;

0 comments on commit 63db097

Please sign in to comment.
You can’t perform that action at this time.