aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Sprehn2010-10-29 12:19:22 -0700
committerElliott Sprehn2010-10-29 12:19:22 -0700
commit9a532002cf490a3e26a827e2eab9c1c3d834e2b8 (patch)
treeb399736d322dc40523b64d56d6b4b9f9bcb9a867
parent5524d2b0fb9b87ef0d1beec092337f836a1043a8 (diff)
downloadangular.js-9a532002cf490a3e26a827e2eab9c1c3d834e2b8.tar.bz2
Auto generate all the jQuery get/set methods
-rw-r--r--src/scenario/dsl.js27
-rw-r--r--test/scenario/dslSpec.js11
2 files changed, 28 insertions, 10 deletions
diff --git a/src/scenario/dsl.js b/src/scenario/dsl.js
index 358f1fce..8235e9e0 100644
--- a/src/scenario/dsl.js
+++ b/src/scenario/dsl.js
@@ -251,6 +251,10 @@ angular.scenario.dsl('select', function() {
* element(selector, label).query(fn) executes fn(selectedElements, done)
*/
angular.scenario.dsl('element', function() {
+ var VALUE_METHODS = [
+ 'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width',
+ 'innerWidth', 'outerWidth', 'position', 'scrollLeft', 'scrollTop', 'offset'
+ ];
var chain = {};
chain.count = function() {
@@ -288,22 +292,25 @@ angular.scenario.dsl('element', function() {
});
};
- chain.val = function(value) {
- var futureName = 'element ' + this.label + ' value';
- if (value) {
- futureName = 'element ' + this.label + ' set value to ' + value;
- }
- return this.addFutureAction(futureName, function($window, $document, done) {
- done(null, $document.elements().val(value));
- });
- };
-
chain.query = function(fn) {
return this.addFutureAction('element ' + this.label + ' custom query', function($window, $document, done) {
fn.call(this, $document.elements(), done);
});
};
+ angular.foreach(VALUE_METHODS, function(methodName) {
+ chain[methodName] = function(value) {
+ var futureName = 'element ' + this.label + ' ' + methodName;
+ if (value) {
+ futureName = 'element ' + this.label + ' set ' + methodName + ' to ' + value;
+ }
+ return this.addFutureAction(futureName, function($window, $document, done) {
+ var element = $document.elements();
+ done(null, element[methodName].call(element, value));
+ });
+ };
+ });
+
return function(selector, label) {
this.dsl.using(selector, label);
return chain;
diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js
index 50d37961..ecb5d3e7 100644
--- a/test/scenario/dslSpec.js
+++ b/test/scenario/dslSpec.js
@@ -215,6 +215,17 @@ describe("angular.scenario.dsl", function() {
expect(doc.find('input').val()).toEqual('baz');
});
+ it('should add all jQuery property methods', function() {
+ var METHODS = [
+ 'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width',
+ 'innerWidth', 'outerWidth', 'position', 'scrollLeft', 'scrollTop', 'offset'
+ ];
+ var chain = $root.dsl.element('input');
+ angular.foreach(METHODS, function(name) {
+ expect(angular.isFunction(chain[name])).toBeTruthy();
+ });
+ });
+
it('should execute custom query', function() {
doc.append('<a id="test" href="http://example.com/myUrl"></a>');
$root.dsl.element('#test').query(function(elements, done) {