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

Commit 249a1d8

Browse files
adam33IgorMinar
authored andcommitted
fix(scenario-runner): support data-ng and x-ng based attributes
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
1 parent fdf85bf commit 249a1d8

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
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+
angular.forEach(['[ng-','[data-ng-','[x-ng-'], function(value, index){
123+
result = result.add(selector.replace(NG, value), $document);
124+
});
123125
}
124126
if (!result.length) {
125127
throw {

test/ngScenario/SpecRunnerSpec.js

-1
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,4 @@ describe('angular.scenario.SpecRunner', function() {
173173
'SpecEnd'
174174
]);
175175
});
176-
177176
});

test/ngScenario/dslSpec.js

+38
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,30 @@ describe("angular.scenario.dsl", function() {
217217
expect(doc.find('[ng-model="test"]').val()).toEqual('A');
218218
});
219219

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+
243+
220244
it('should select option by name', function() {
221245
doc.append(
222246
'<select ng-model="test">' +
@@ -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');

0 commit comments

Comments
 (0)