Skip to content

Commit

Permalink
[BUGFIX beta] fillIn only sets value to first match.
Browse files Browse the repository at this point in the history
Currently, `fillIn` sets the new value to all matches, though the events are
only fired for the first one, making Ember only aware of that one.

This can cause a problem while trying to _debug_ a test.

Fixes emberjs#14018
  • Loading branch information
Serabe committed Aug 5, 2016
1 parent 138de8f commit 7e9176d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-testing/lib/helpers/fill_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function fillIn(app, selector, contextOrText, text) {
el = $el[0];
focus(el);

$el.val(text);
$el.eq(0).val(text);
fireEvent(el, 'input');
fireEvent(el, 'change');

Expand Down
22 changes: 22 additions & 0 deletions packages/ember-testing/tests/helpers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,28 @@ QUnit.test('`fillIn` fires `input` and `change` events in the proper order', fun
return wait();
});

QUnit.test('`fillIn` only sets the value in the first matched element', function() {
let fillIn, find, visit, andThen, wait;

setTemplate('index', compile('<input type="text" id="first" class="in-test"><input type="text" id="second" class="in-test">'));
run(App, App.advanceReadiness);

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

visit('/');
fillIn('input.in-test', 'new value');
andThen(function() {
equal(find('#first').val(), 'new value');
equal(find('#second').val(), '');
});

return wait();
});

QUnit.test('`triggerEvent accepts an optional options hash and context', function() {
expect(3);

Expand Down

0 comments on commit 7e9176d

Please sign in to comment.