Skip to content

Commit 641fc8d

Browse files
author
Steven Orvell
committed
Adds test that reveals issue with @apply
When this test passes, issue #117 should be addressed.
1 parent b4c5f51 commit 641fc8d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/test/lit-element_styling_test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,60 @@ suite('Styling', () => {
252252
assert.equal(getComputedStyleValue(div!, 'border-top-width').trim(), '10px');
253253
});
254254

255+
test.only('@apply renders in nested elements when sub-element renders separately first', async () => {
256+
class I extends LitElement {
257+
render() { return html`
258+
<style>
259+
:host {
260+
display: block;
261+
width: 100px;
262+
height: 100px;
263+
border: 2px solid black;
264+
margin-top: 10px;
265+
@apply --bag;
266+
}
267+
</style>Hi`;
268+
}
269+
}
270+
customElements.define('x-applied', I);
271+
272+
const name = generateElementName();
273+
class E extends LitElement {
274+
applied: HTMLElement|undefined;
275+
276+
render() { return html`
277+
<style>
278+
:host {
279+
--bag: {
280+
border: 10px solid black;
281+
margin-top: 2px;
282+
}
283+
}
284+
</style>
285+
<x-applied></x-applied>`;
286+
}
287+
288+
firstUpdated() {
289+
this.applied = this.shadowRoot!.querySelector('x-applied') as LitElement;
290+
}
291+
}
292+
customElements.define(name, E);
293+
294+
const firstApplied = document.createElement('x-applied') as I;
295+
container.appendChild(firstApplied);
296+
const el = document.createElement(name) as E;
297+
container.appendChild(el);
298+
299+
// Workaround for Safari 9 Promise timing bugs.
300+
await firstApplied.updateComplete && el.updateComplete && await (el.applied as I)!.updateComplete;
301+
302+
await nextFrame();
303+
assert.equal(getComputedStyleValue(firstApplied!, 'border-top-width').trim(), '2px');
304+
assert.equal(getComputedStyleValue(firstApplied!, 'margin-top').trim(), '10px');
305+
assert.equal(getComputedStyleValue(el.applied!, 'border-top-width').trim(), '10px');
306+
assert.equal(getComputedStyleValue(el.applied!, 'margin-top').trim(), '2px');
307+
});
308+
255309
});
256310

257311
suite('ShadyDOM', () => {

0 commit comments

Comments
 (0)