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

Commit ad7ce0d

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 085e0ea commit ad7ce0d

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">' +
@@ -542,6 +566,20 @@ describe("angular.scenario.dsl", function() {
542566
chain.enter('foo');
543567
expect(_jQuery('input[ng-model="test.input"]').val()).toEqual('foo');
544568
});
569+
it('should change value in text input in data-ng form', function() {
570+
doc.append('<input data-ng-model="test.input" value="something">');
571+
var chain = $root.dsl.input('test.input');
572+
chain.enter('foo');
573+
expect(_jQuery('input[data-ng-model="test.input"]').val()).toEqual('foo');
574+
});
575+
it('should change value in text input in x-ng form', function() {
576+
doc.append('<input x-ng-model="test.input" value="something">');
577+
var chain = $root.dsl.input('test.input');
578+
chain.enter('foo');
579+
expect(_jQuery('input[x-ng-model="test.input"]').val()).toEqual('foo');
580+
});
581+
582+
545583

546584
it('should return error if no input exists', function() {
547585
var chain = $root.dsl.input('test.input');

0 commit comments

Comments
 (0)