| 1 |
/** |
| 2 |
* @license |
| 3 |
* Copyright 2022 Google LLC |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
import {html} from 'lit'; |
| 8 |
import {expect, html as testingHtml, fixture} from '@open-wc/testing'; |
| 9 |
|
| 10 |
const data = new Array(100).fill('').map((_, idx) => idx); |
| 11 |
|
| 12 |
export async function testBehavior() { |
| 13 |
await import('../../../lit-virtualizer.js'); |
| 14 |
const example = (await fixture( |
| 15 |
testingHtml` |
| 16 |
<lit-virtualizer |
| 17 |
.items=${data} |
| 18 |
.renderItem=${(item: number) => html`<div>Item ${item}</div>`} |
| 19 |
></lit-virtualizer> |
| 20 |
` |
| 21 |
)) as HTMLElement & {layoutComplete: Promise<void>}; |
| 22 |
await customElements.whenDefined('lit-virtualizer'); |
| 23 |
expect(example).to.be.instanceof(customElements.get('lit-virtualizer')); |
| 24 |
await example.layoutComplete; |
| 25 |
expect(example.textContent).to.contain('Item 0'); |
| 26 |
document.body.scrollTo({top: 100000}); |
| 27 |
await example.layoutComplete; |
| 28 |
expect(example.textContent).to.contain('Item 99'); |
| 29 |
} |