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

Commit

Permalink
fix(scenario): don't trigger input events on IE9
Browse files Browse the repository at this point in the history
input.enter() should trigger 'change' rather than 'input' event on IE9 because
input events on IE9 are broken and angular doesn't rely on them
  • Loading branch information
IgorMinar committed Jan 17, 2013
1 parent c97c53d commit 8b9e6c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ngScenario/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ angular.scenario.dsl('binding', function() {
*/
angular.scenario.dsl('input', function() {
var chain = {};
var supportInputEvent = 'oninput' in document.createElement('div');
var supportInputEvent = 'oninput' in document.createElement('div') && msie != 9;

chain.enter = function(value, event) {
return this.addFutureAction("input '" + this.name + "' enter '" + value + "'", function($window, $document, done) {
var input = $document.elements('[ng\\:model="$1"]', this.name).filter(':input');
input.val(value);
input.trigger(event || supportInputEvent && 'input' || 'change');
input.trigger(event || (supportInputEvent ? 'input' : 'change'));
done();
});
};
Expand Down
24 changes: 17 additions & 7 deletions test/ngScenario/dslSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe("angular.scenario.dsl", function() {
$root.dsl.select('test').options('A', 'B');
expect($root.futureError).toMatch(/did not match/);
});

it('should fail to select an option that does not exist', function(){
doc.append(
'<select ng-model="test">' +
Expand Down Expand Up @@ -596,12 +596,22 @@ describe("angular.scenario.dsl", function() {
});

describe('Input', function() {
it('should change value in text input', function() {
doc.append('<input ng-model="test.input" value="something">');
var chain = $root.dsl.input('test.input');
chain.enter('foo');
expect(_jQuery('input[ng-model="test.input"]').val()).toEqual('foo');
});
it('should change value in text input', inject(function($compile) {
runs(function() {
element = $compile('<input ng-model="test.input" value="something">')($root);
doc.append(element);
var chain = $root.dsl.input('test.input');
chain.enter('foo');
expect(_jQuery('input[ng-model="test.input"]').val()).toEqual('foo');
});

// cleanup the event queue
waits(0);

runs(function() {
expect($root.test.input).toBe('foo');
});
}));

it('should change value in text input in dash form', function() {
doc.append('<input ng-model="test.input" value="something">');
Expand Down

0 comments on commit 8b9e6c3

Please sign in to comment.