Skip to content

Commit

Permalink
fix: prevent incorrect console warning
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Jan 21, 2020
1 parent b97af02 commit adfb07a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vaadin-checkbox-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
Expand Down
32 changes: 32 additions & 0 deletions test/vaadin-checkbox-group_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit adfb07a

Please sign in to comment.