Skip to content

Commit f4f78a9

Browse files
committed
Merge pull request #11708 from cibernox/fillIn-triggers-oninput-event
[BUGFIX beta] fillIn test helper triggers `input` event.
2 parents 04dd84c + 14124e9 commit f4f78a9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/ember-testing/lib/helpers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ function fillIn(app, selector, contextOrText, text) {
182182
$el = app.testHelpers.findWithAssert(selector, context);
183183
focus($el);
184184
run(function() {
185-
$el.val(text).change();
185+
$el.val(text);
186+
$el.trigger('input');
187+
$el.change();
186188
});
187189
return app.testHelpers.wait();
188190
}

packages/ember-testing/tests/helpers_test.js

+33
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,39 @@ QUnit.test('`fillIn` focuses on the element', function() {
581581
});
582582
});
583583

584+
QUnit.test('`fillIn` fires `input` and `change` events in the proper order', function() {
585+
expect(1);
586+
587+
var fillIn, visit, andThen;
588+
var events = [];
589+
App.IndexController = Ember.Controller.extend({
590+
actions: {
591+
oninputHandler(e) {
592+
events.push(e.type);
593+
},
594+
onchangeHanlders(e) {
595+
events.push(e.type);
596+
}
597+
}
598+
});
599+
600+
App.IndexView = EmberView.extend({
601+
template: compile('<input type="text" id="first" oninput={{action "oninputHandler"}} onchange={{action "onchangeHanlders"}}>')
602+
});
603+
604+
run(App, App.advanceReadiness);
605+
606+
fillIn = App.testHelpers.fillIn;
607+
visit = App.testHelpers.visit;
608+
andThen = App.testHelpers.andThen;
609+
610+
visit('/');
611+
fillIn('#first', 'current value');
612+
andThen(function() {
613+
deepEqual(events, ['input', 'change'], '`input` and `change` events are fired in the proper order');
614+
});
615+
});
616+
584617
if (isEnabled('ember-testing-checkbox-helpers')) {
585618
QUnit.test('`check` ensures checkboxes are `checked` state for checkboxes', function() {
586619
expect(2);

0 commit comments

Comments
 (0)