Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(scenario-runner): support data-ng and x-ng based attributes
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 #1020
  • Loading branch information
adam33 authored and IgorMinar committed Oct 31, 2012
1 parent 085e0ea commit ad7ce0d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
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);
angular.forEach(['[ng-','[data-ng-','[x-ng-'], function(value, index){
result = result.add(selector.replace(NG, value), $document);
});
}
if (!result.length) {
throw {
Expand Down
1 change: 0 additions & 1 deletion test/ngScenario/SpecRunnerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,4 @@ describe('angular.scenario.SpecRunner', function() {
'SpecEnd'
]);
});

});
38 changes: 38 additions & 0 deletions test/ngScenario/dslSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ describe("angular.scenario.dsl", function() {
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(
'<select ng-model="test">' +
Expand Down Expand Up @@ -542,6 +566,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

0 comments on commit ad7ce0d

Please sign in to comment.