Skip to content

Commit

Permalink
fix(SpecRunner.js): data-ng and x-ng based attributes are now found
Browse files Browse the repository at this point in the history
Prefixed attributes like data-ng-model and x-ng-model were not being
found by the Selector. It was only looking at ng: and ng- prefixed
attributes.
Added a few tests as well to ensure the aforementioned prefixed
attributes are being matched properly.

Closes angular#1020
  • Loading branch information
adam33 committed Oct 30, 2012
1 parent 54b3875 commit f5bcd0a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ngScenario/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior,
});
var result = $document.find(selector);
if (selector.match(NG)) {
result = result.add(selector.replace(NG, '[ng-'), $document);
_jQuery.each(['[ng-','[data-ng-','[x-ng-'], function(index, value){

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Oct 31, 2012

you should be able to use just forEach instead of _jQuery.each

result = result.add(selector.replace(NG, value), $document);
})
}
if (!result.length) {
throw {
Expand Down
39 changes: 39 additions & 0 deletions test/ngScenario/dslSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,30 @@ describe("angular.scenario.dsl", function() {
$root.dsl.select('test').option('A');
expect(doc.find('[ng-model="test"]').val()).toEqual('A');
});

it('should select single option using data-ng', function() {
doc.append(
'<select data-ng-model="test">' +
' <option value=A>one</option>' +
' <option value=B selected>two</option>' +
'</select>'
);
$root.dsl.select('test').option('A');
expect(doc.find('[data-ng-model="test"]').val()).toEqual('A');
});
it('should select single option using x-ng', function() {
doc.append(
'<select x-ng-model="test">' +
' <option value=A>one</option>' +
' <option value=B selected>two</option>' +
'</select>'
);
$root.dsl.select('test').option('A');
expect(doc.find('[x-ng-model="test"]').val()).toEqual('A');
});




it('should select option by name', function() {
doc.append(
Expand Down Expand Up @@ -574,6 +598,20 @@ describe("angular.scenario.dsl", function() {
chain.enter('foo');
expect(_jQuery('input[ng-model="test.input"]').val()).toEqual('foo');
});
it('should change value in text input in data-ng form', function() {
doc.append('<input data-ng-model="test.input" value="something">');
var chain = $root.dsl.input('test.input');
chain.enter('foo');
expect(_jQuery('input[data-ng-model="test.input"]').val()).toEqual('foo');
});
it('should change value in text input in x-ng form', function() {
doc.append('<input x-ng-model="test.input" value="something">');
var chain = $root.dsl.input('test.input');
chain.enter('foo');
expect(_jQuery('input[x-ng-model="test.input"]').val()).toEqual('foo');
});



it('should return error if no input exists', function() {
var chain = $root.dsl.input('test.input');
Expand Down Expand Up @@ -650,5 +688,6 @@ describe("angular.scenario.dsl", function() {
expect($root.futureError).toMatch(/did not match/);
});
});

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Oct 31, 2012

remove

});
});

1 comment on commit f5bcd0a

@IgorMinar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise this look very good! Have you signed our CLA?

For individuals (a simple click-through form):
http://code.google.com/legal/individual-cla-v1.0.html

For corporations (print, sign and scan+email, fax or mail):
http://code.google.com/legal/corporate-cla-v1.0.html

Please sign in to comment.