Created
January 29, 2012 20:27
-
-
Save vojtajina/1700488 to your computer and use it in GitHub Desktop.
Angular: Access to iframe's jQuery
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript" src="http://code.angularjs.org/0.10.6/angular-scenario-0.10.6.js" ng:autotest></script> | |
<script type="text/javascript"> | |
angular.scenario.dsl('appElement', function() { | |
return function(selector, fn) { | |
return this.addFutureAction('element ' + selector, function($window, $document, done) { | |
fn.call(this, $window.angular.element(selector)); | |
done(); | |
}); | |
}; | |
}); | |
describe('just one', function() { | |
beforeEach(function() { | |
browser().navigateTo('test-case.html'); | |
}); | |
it('should fire event listeners', function() { | |
// this works fine, because scenario runner fires the real events | |
// see https://github.com/vojtajina/angular.js/blob/master/src/scenario/Scenario.js#L330 | |
element('input[address]').click(); | |
pause(); | |
// keypress does not work, because scenario runner patches only click|change|keydown | |
// and jQuery does not fire browser event | |
element('input[address]').query(function(elm, done) { | |
elm.trigger('keypress'); | |
done(); | |
}); | |
pause(); | |
// this works, as this custom dsl gives you access to app (iframe) instance of jQuery | |
appElement('input[address]', function(elm) { | |
elm.trigger('keypress'); | |
}); | |
}); | |
}); | |
</script> | |
<title></title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or 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
<!DOCTYPE html> | |
<html ng-app> | |
<head> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script type="text/javascript" src="http://code.angularjs.org/0.10.6/angular-0.10.6.min.js"></script> | |
<script type="text/javascript"> | |
angular.directive('address', function() { | |
return function(element) { | |
element.bind('keypress', function() { | |
console.log('keypress'); | |
}); | |
element.bind('click', function() { | |
console.log('click'); | |
}) | |
}; | |
}); | |
</script> | |
<title></title> | |
</head> | |
<body> | |
Testing simple directive with click + keypress listeners... | |
<input type="text" ng:model="data.place" address /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that
appElement
produces the following error when run via karma withsingleRun = true
However it works without error when
singleRun = false
. BTW I'm running karma via grunt-karma