| 1 |
/** |
| 2 |
* @license |
| 3 |
* Copyright 2022 Google LLC |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
import {ignoreBenignErrors} from '../helpers.js'; |
| 8 |
import {html, css, LitElement} from 'lit'; |
| 9 |
import {ref} from 'lit/directives/ref.js'; |
| 10 |
import {customElement, property} from 'lit/decorators.js'; |
| 11 |
import {virtualize} from '../../virtualize.js'; |
| 12 |
import {html as testingHtml, fixture} from '@open-wc/testing'; |
| 13 |
|
| 14 |
@customElement('immediate-sizing') |
| 15 |
class ImmediateSizing extends LitElement { |
| 16 |
static styles = css` |
| 17 |
.list { |
| 18 |
width: 100px; |
| 19 |
height: 100; |
| 20 |
} |
| 21 |
.item { |
| 22 |
height: 50px; |
| 23 |
margin: 0; |
| 24 |
padding: 0; |
| 25 |
} |
| 26 |
.sized { |
| 27 |
width: 10px; |
| 28 |
} |
| 29 |
`; |
| 30 |
|
| 31 |
@property({type: Array, attribute: false}) |
| 32 |
public items: Array<string> = []; |
| 33 |
|
| 34 |
render() { |
| 35 |
return html` <div class="list"> |
| 36 |
${virtualize({ |
| 37 |
scroller: true, |
| 38 |
items: this.items, |
| 39 |
renderItem: (item) => html`<div class="item">[${item}]</div>`, |
| 40 |
})} |
| 41 |
<div ${ref((el?: Element) => el?.classList.toggle('sized'))}></div> |
| 42 |
</div>`; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
describe("Don't behave badly when sizing element before initialization is complete ", () => { |
| 47 |
ignoreBenignErrors(beforeEach, afterEach); |
| 48 |
|
| 49 |
it('should render the element without error', async () => { |
| 50 |
await fixture<ImmediateSizing>( |
| 51 |
testingHtml` |
| 52 |
<immediate-sizing .items=${['item 1', 'item 2']}></immediate-sizing> |
| 53 |
` |
| 54 |
); |
| 55 |
}); |
| 56 |
}); |