From adfb07a035d11413a169a44c146fefdaaf1bd179 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Tue, 21 Jan 2020 16:08:00 +0200 Subject: [PATCH] fix: prevent incorrect console warning --- 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 a865a79..c970e30 100644 --- a/src/vaadin-checkbox-group.html +++ b/src/vaadin-checkbox-group.html @@ -210,7 +210,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', () => {