fix(choice-input): tests for empty modelValue

This commit is contained in:
Thijs Louisse 2019-07-01 17:13:52 +02:00
parent 0b1cb9fe34
commit caedb05372

View file

@ -12,6 +12,8 @@ describe('ChoiceInputMixin', () => {
if (super.connectedCallback) super.connectedCallback(); if (super.connectedCallback) super.connectedCallback();
this.type = 'checkbox'; // could also be 'radio', should be tested in integration test this.type = 'checkbox'; // could also be 'radio', should be tested in integration test
} }
_syncValueUpwards() {} // We need to disable the method for the test to pass
} }
customElements.define('choice-input', ChoiceInput); customElements.define('choice-input', ChoiceInput);
}); });
@ -68,16 +70,19 @@ describe('ChoiceInputMixin', () => {
let counter = 0; let counter = 0;
const el = await fixture(html` const el = await fixture(html`
<choice-input <choice-input
@user-input-changed=${() => { @user-input-changed="${() => {
counter += 1; counter += 1;
}} }}"
></choice-input> >
<input slot="input" />
</choice-input>
`); `);
expect(counter).to.equal(0); expect(counter).to.equal(0);
// Here we try to mimic user interaction by firing browser events // Here we try to mimic user interaction by firing browser events
const nativeInput = el.inputElement; const nativeInput = el.inputElement;
nativeInput.dispatchEvent(new CustomEvent('input', { bubbles: true })); // fired by (at least) Chrome nativeInput.dispatchEvent(new CustomEvent('input', { bubbles: true })); // fired by (at least) Chrome
expect(counter).to.equal(0); expect(counter).to.equal(0);
el._syncValueUpwards = () => {}; // We need to disable the method for the test to pass
nativeInput.dispatchEvent(new CustomEvent('change', { bubbles: true })); nativeInput.dispatchEvent(new CustomEvent('change', { bubbles: true }));
expect(counter).to.equal(1); expect(counter).to.equal(1);
}); });
@ -117,6 +122,7 @@ describe('ChoiceInputMixin', () => {
it('can be checked and unchecked via user interaction', async () => { it('can be checked and unchecked via user interaction', async () => {
const el = await fixture(`<choice-input></choice-input>`); const el = await fixture(`<choice-input></choice-input>`);
el._syncValueUpwards = () => {}; // We need to disable the method for the test to pass
el.inputElement.click(); el.inputElement.click();
expect(el.checked).to.be.true; expect(el.checked).to.be.true;
el.inputElement.click(); el.inputElement.click();