Skip to content

Commit

Permalink
test: simplify attr-for-value test
Browse files Browse the repository at this point in the history
  • Loading branch information
Haprog committed Mar 26, 2019
1 parent a2f21de commit 9994066
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions test/vaadin-combo-box-light.html
Expand Up @@ -154,14 +154,6 @@
describe('vaadin-combobox-light-attr-for-value', () => {
let comboBox, customInput, ironInput, nativeInput;

function whenIronInputReady(ironInput, callback) {
if (ironInput.inputElement) {
callback();
} else {
ironInput.addEventListener('iron-input-ready', callback);
}
}

beforeEach(() => {
comboBox = fixture('combobox-light-attr-for-value');
comboBox.items = ['foo', 'bar', 'baz'];
Expand All @@ -185,35 +177,27 @@
expect(customInput.customValue).to.eql('foo');
});

it('should bind the input value correctly when getting input', done => {
it('should bind the input value correctly when getting input', () => {
// Empty string by default.
expect(comboBox._inputElementValue).to.eql('');
expect(customInput.customValue).to.eql('');
expect(nativeInput.value).to.eql('');

// We need to wait until <iron-input> is ready before trying to input text
// into the input, otherwise the test will fail when iron-input throws
// an error in `_onInput` because it tries to read `inputElement.value`
// but `inputElement` may still be undefined because iron-input hasn't yet
// detected the slotted <input> element.
whenIronInputReady(ironInput, () => {
// Use a timeout to get out of "iron-input-ready" event context, otherwise
// any thrown error (e.g. failed assertion) will result in a huge obscure
// error message in Firefox without any info about the assertion failure.
setTimeout(() => {

// Simulate typing an option with a keyboard and confirming it via Enter
nativeInput.value = 'foo';
fire('input', nativeInput);
MockInteractions.pressAndReleaseKeyOn(nativeInput, 13, null, 'Enter');

expect(comboBox.value).to.eql('foo');
expect(comboBox._inputElementValue).to.eql('foo');
expect(customInput.customValue).to.eql('foo');

done();
}, 0);
});
// Make sure the slotted <input> has been detected by <iron-input>
// before trying to modify the value of the <input>.
// Otherwise iron-input will throw an error (in `_onInput`) because
// it tries to read `inputElement.value` but `inputElement` is still
// undefined.
ironInput._observer.flush();

// Simulate typing an option with a keyboard and confirming it via Enter
nativeInput.value = 'foo';
fire('input', nativeInput);
MockInteractions.pressAndReleaseKeyOn(nativeInput, 13, null, 'Enter');

expect(comboBox.value).to.eql('foo');
expect(comboBox._inputElementValue).to.eql('foo');
expect(customInput.customValue).to.eql('foo');
});
});
});
Expand Down

0 comments on commit 9994066

Please sign in to comment.