Skip to content

Commit f5bcd0a

Browse files
committed
fix(SpecRunner.js): data-ng and x-ng based attributes are now found
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
1 parent 54b3875 commit f5bcd0a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/ngScenario/SpecRunner.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior,
119119
});
120120
var result = $document.find(selector);
121121
if (selector.match(NG)) {
122-
result = result.add(selector.replace(NG, '[ng-'), $document);
122+
_jQuery.each(['[ng-','[data-ng-','[x-ng-'], function(index, value){
123+
result = result.add(selector.replace(NG, value), $document);
124+
})
123125
}
124126
if (!result.length) {
125127
throw {

test/ngScenario/dslSpec.js

+39
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ describe("angular.scenario.dsl", function() {
216216
$root.dsl.select('test').option('A');
217217
expect(doc.find('[ng-model="test"]').val()).toEqual('A');
218218
});
219+
220+
it('should select single option using data-ng', function() {
221+
doc.append(
222+
'<select data-ng-model="test">' +
223+
' <option value=A>one</option>' +
224+
' <option value=B selected>two</option>' +
225+
'</select>'
226+
);
227+
$root.dsl.select('test').option('A');
228+
expect(doc.find('[data-ng-model="test"]').val()).toEqual('A');
229+
});
230+
it('should select single option using x-ng', function() {
231+
doc.append(
232+
'<select x-ng-model="test">' +
233+
' <option value=A>one</option>' +
234+
' <option value=B selected>two</option>' +
235+
'</select>'
236+
);
237+
$root.dsl.select('test').option('A');
238+
expect(doc.find('[x-ng-model="test"]').val()).toEqual('A');
239+
});
240+
241+
242+
219243

220244
it('should select option by name', function() {
221245
doc.append(
@@ -574,6 +598,20 @@ describe("angular.scenario.dsl", function() {
574598
chain.enter('foo');
575599
expect(_jQuery('input[ng-model="test.input"]').val()).toEqual('foo');
576600
});
601+
it('should change value in text input in data-ng form', function() {
602+
doc.append('<input data-ng-model="test.input" value="something">');
603+
var chain = $root.dsl.input('test.input');
604+
chain.enter('foo');
605+
expect(_jQuery('input[data-ng-model="test.input"]').val()).toEqual('foo');
606+
});
607+
it('should change value in text input in x-ng form', function() {
608+
doc.append('<input x-ng-model="test.input" value="something">');
609+
var chain = $root.dsl.input('test.input');
610+
chain.enter('foo');
611+
expect(_jQuery('input[x-ng-model="test.input"]').val()).toEqual('foo');
612+
});
613+
614+
577615

578616
it('should return error if no input exists', function() {
579617
var chain = $root.dsl.input('test.input');
@@ -650,5 +688,6 @@ describe("angular.scenario.dsl", function() {
650688
expect($root.futureError).toMatch(/did not match/);
651689
});
652690
});
691+
653692
});
654693
});

0 commit comments

Comments
 (0)