Skip to content

Commit

Permalink
[BUGFIX beta] fillIn test helper triggers input event.
Browse files Browse the repository at this point in the history
The new `<input type="text" oninput={{action "search"}}>` is very fast
but at the moment is unusable bacause ember test helpers doesn't fire
that event.

Fixed.
  • Loading branch information
cibernox committed Jul 10, 2015
1 parent 04dd84c commit 14124e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ember-testing/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ function fillIn(app, selector, contextOrText, text) {
$el = app.testHelpers.findWithAssert(selector, context);
focus($el);
run(function() {
$el.val(text).change();
$el.val(text);
$el.trigger('input');
$el.change();
});
return app.testHelpers.wait();
}
Expand Down
33 changes: 33 additions & 0 deletions packages/ember-testing/tests/helpers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,39 @@ QUnit.test('`fillIn` focuses on the element', function() {
});
});

QUnit.test('`fillIn` fires `input` and `change` events in the proper order', function() {
expect(1);

var fillIn, visit, andThen;
var events = [];
App.IndexController = Ember.Controller.extend({
actions: {
oninputHandler(e) {
events.push(e.type);
},
onchangeHanlders(e) {
events.push(e.type);
}
}
});

App.IndexView = EmberView.extend({
template: compile('<input type="text" id="first" oninput={{action "oninputHandler"}} onchange={{action "onchangeHanlders"}}>')
});

run(App, App.advanceReadiness);

fillIn = App.testHelpers.fillIn;
visit = App.testHelpers.visit;
andThen = App.testHelpers.andThen;

visit('/');
fillIn('#first', 'current value');
andThen(function() {
deepEqual(events, ['input', 'change'], '`input` and `change` events are fired in the proper order');
});
});

if (isEnabled('ember-testing-checkbox-helpers')) {
QUnit.test('`check` ensures checkboxes are `checked` state for checkboxes', function() {
expect(2);
Expand Down

0 comments on commit 14124e9

Please sign in to comment.