Skip to content

e2e test runner can now test manually bootstrapped angularjs applications #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions src/ngScenario/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,43 @@ angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorF
* @param {function()} action The callback to execute. function($window, $document)
* $document is a jQuery wrapped document.
*/
angular.scenario.Application.prototype.executeAction = function(action) {
var self = this;
var $window = this.getWindow_();
if (!$window.document) {
throw 'Sandbox Error: Application document not accessible.';
}
if (!$window.angular) {
return action.call(this, $window, _jQuery($window.document));
}
angularInit($window.document, function(element) {
var $injector = $window.angular.element(element).injector();
var $element = _jQuery(element);
angular.scenario.Application.prototype.executeAction = function(action)
{
var self = this;
var $window = this.getWindow_();
if (!$window.document) {
throw 'Sandbox Error: Application document not accessible.';
}

if (!$window.angular) {
return action.call(this, $window, _jQuery($window.document));
}

var initialisedWithNgAppDirective = false;

// angularInit calls this function only if ng-app directive is detected
var initFn = function(element) {
initialisedWithNgAppDirective = true;

var $injector = $window.angular.element(element).injector();
var $element = _jQuery(element);

$element.injector = function() {
return $injector;
};

$injector.invoke(function($browser) {
$browser.notifyWhenNoOutstandingRequests(function() {
action.call(self, $window, $element);
});
});
};

$element.injector = function() {
return $injector;
};
// original implementation searches for ng-app and attaches to angular if found
angularInit($window.document, initFn);

$injector.invoke(function($browser){
$browser.notifyWhenNoOutstandingRequests(function() {
action.call(self, $window, $element);
});
});
});
if (!initialisedWithNgAppDirective) {
// ng-app not found so manually attaching to the root of document
initFn($window.document);
}
};