Skip to content

Commit

Permalink
Merge a9d984c into 051c642
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-fix committed Sep 17, 2019
2 parents 051c642 + a9d984c commit 732f906
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/vaadin-list-box.html
Expand Up @@ -91,11 +91,20 @@
ready() {
super.ready();
this.setAttribute('role', 'list');

setTimeout(this._checkImport.bind(this), 2000);
}

get _scrollerElement() {
return this.shadowRoot.querySelector('[part="items"]');
}

_checkImport() {
var item = this.querySelector('vaadin-item');
if (item && !(item instanceof Polymer.Element)) {
console.warn(`Make sure you have imported the vaadin-item element.`);
}
}
}

customElements.define(ListBoxElement.is, ListBoxElement);
Expand Down
57 changes: 57 additions & 0 deletions test/import-warning-test.html
@@ -0,0 +1,57 @@
<!doctype html>

<head>
<meta charset="UTF-8">
<title>vaadin-list-box tests</title>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../vaadin-list-box.html">
</head>

<body>
<test-fixture id="default">
<template>
<vaadin-list-box>
<vaadin-item>Foo</vaadin-item>
<vaadin-item>Bar</vaadin-item>
</vaadin-list-box>
</template>
</test-fixture>

<script>
describe(`import warning for vaadin-item`, () => {
let listbox;

function isV2() {
return window['Polymer'] && window['Polymer']['version'] && window['Polymer']['version'].indexOf('2') === 0;
}

beforeEach(() => listbox = fixture('default'));

it('should warn if not imported', () => {
sinon.stub(console, 'warn');
// Emulate setTimeout run from ready
listbox._checkImport();
expect(console.warn.callCount).to.equal(1);
console.warn.restore();
});

it('should not warn for present import', (done) => {
if (isV2()) {
Polymer.Base.importHref(`../../vaadin-item/vaadin-item.html`, () => {
sinon.stub(console, 'warn');
listbox._checkImport();
expect(console.warn.called).to.be.false;
console.warn.restore();
done();
});
} else {
// importHref is removed in Polymer 3 stable release, skip the test.
done();
}
});
});
</script>
</body>
1 change: 1 addition & 0 deletions test/test-suites.js
@@ -1,4 +1,5 @@

window.VaadinListBoxSuites = [
'import-warning-test.html',
'list-box-test.html'
];

0 comments on commit 732f906

Please sign in to comment.