From 4f85b53e013dda15211b79c798294af423ba5267 Mon Sep 17 00:00:00 2001 From: Serhii Kulykov Date: Tue, 21 Jan 2020 16:16:26 +0200 Subject: [PATCH] fix: prevent incorrect console warning (#162) --- src/vaadin-checkbox-group.html | 6 +++++- test/vaadin-checkbox-group_test.html | 32 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/vaadin-checkbox-group.html b/src/vaadin-checkbox-group.html index f88c650..dff2c66 100644 --- a/src/vaadin-checkbox-group.html +++ b/src/vaadin-checkbox-group.html @@ -211,7 +211,11 @@ } }); - if (addedCheckboxes.some(checkbox => !checkbox.hasAttribute('value'))) { + const hasValue = checkbox => { + const {value} = checkbox; + return checkbox.hasAttribute('value') || value && value !== 'on'; + }; + if (!addedCheckboxes.every(hasValue)) { console.warn('Please add value attribute to all checkboxes in checkbox group'); } }); diff --git a/test/vaadin-checkbox-group_test.html b/test/vaadin-checkbox-group_test.html index 144549d..70cdcdd 100644 --- a/test/vaadin-checkbox-group_test.html +++ b/test/vaadin-checkbox-group_test.html @@ -280,6 +280,38 @@ expect(spy).to.not.be.called; }); + + it('should warn when adding checkbox without value', () => { + sinon.stub(console, 'warn'); + + const checkbox = document.createElement('vaadin-checkbox'); + vaadinCheckboxGroup.appendChild(checkbox); + vaadinCheckboxGroup._observer.flush(); + expect(console.warn.callCount).to.equal(1); + console.warn.restore(); + }); + + it('should not warn when adding checkbox with value attribute', () => { + sinon.stub(console, 'warn'); + + const checkbox = document.createElement('vaadin-checkbox'); + checkbox.setAttribute('value', 'something'); + vaadinCheckboxGroup.appendChild(checkbox); + vaadinCheckboxGroup._observer.flush(); + expect(console.warn.callCount).to.equal(0); + console.warn.restore(); + }); + + it('should not warn when adding checkbox with value property', () => { + sinon.stub(console, 'warn'); + + const checkbox = document.createElement('vaadin-checkbox'); + checkbox.value = 'something'; + vaadinCheckboxGroup.appendChild(checkbox); + vaadinCheckboxGroup._observer.flush(); + expect(console.warn.callCount).to.equal(0); + console.warn.restore(); + }); }); describe('vaadin-checkbox-group validation', () => {