1313 */
1414
1515import '@webcomponents/shadycss/apply-shim.min.js' ;
16+
1617import {
1718 html ,
1819 LitElement ,
1920} from '../lit-element.js' ;
2021
21- import { generateElementName , nextFrame , getComputedStyleValue } from './test-helpers.js' ;
22+ import {
23+ generateElementName ,
24+ getComputedStyleValue ,
25+ nextFrame
26+ } from './test-helpers.js' ;
2227
2328declare global {
2429 interface Window {
@@ -45,7 +50,8 @@ suite('Styling', () => {
4550 test ( 'content shadowRoot is styled' , async ( ) => {
4651 const name = generateElementName ( ) ;
4752 customElements . define ( name , class extends LitElement {
48- render ( ) { return html `
53+ render ( ) {
54+ return html `
4955 < style >
5056 div {
5157 border : 2px solid blue;
@@ -69,7 +75,8 @@ suite('Styling', () => {
6975 </ style > ` ;
7076 const name = generateElementName ( ) ;
7177 customElements . define ( name , class extends LitElement {
72- render ( ) { return html `
78+ render ( ) {
79+ return html `
7380 < style >
7481 div {
7582 border : 2px solid blue;
@@ -89,7 +96,8 @@ suite('Styling', () => {
8996 test ( 'custom properties render' , async ( ) => {
9097 const name = generateElementName ( ) ;
9198 customElements . define ( name , class extends LitElement {
92- render ( ) { return html `
99+ render ( ) {
100+ return html `
93101 < style >
94102 : host {
95103 - - bor der: 8px solid red;
@@ -110,7 +118,8 @@ suite('Styling', () => {
110118
111119 test ( 'custom properties flow to nested elements' , async ( ) => {
112120 customElements . define ( 'x-inner' , class extends LitElement {
113- render ( ) { return html `
121+ render ( ) {
122+ return html `
114123 < style >
115124 div {
116125 border : var (--border );
@@ -123,7 +132,8 @@ suite('Styling', () => {
123132 class E extends LitElement {
124133 inner : LitElement | null = null ;
125134
126- render ( ) { return html `
135+ render ( ) {
136+ return html `
127137 < style >
128138 x-inner {
129139 --border : 8px solid red;
@@ -148,72 +158,76 @@ suite('Styling', () => {
148158 assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) , '8px' ) ;
149159 } ) ;
150160
151- test ( 'elements with custom properties can move between elements' , async ( ) => {
152- customElements . define ( 'x-inner1' , class extends LitElement {
153- render ( ) { return html `
161+ test ( 'elements with custom properties can move between elements' ,
162+ async ( ) => {
163+ customElements . define ( 'x-inner1' , class extends LitElement {
164+ render ( ) {
165+ return html `
154166 < style >
155167 div {
156168 border : var (--border );
157169 }
158170 </ style >
159171 < div > Testing...</ div > ` ;
160- }
161- } ) ;
162- const name1 = generateElementName ( ) ;
163- customElements . define ( name1 , class extends LitElement {
164-
165- inner : Element | null = null ;
166-
167- render ( ) { return html `
172+ }
173+ } ) ;
174+ const name1 = generateElementName ( ) ;
175+ customElements . define ( name1 , class extends LitElement {
176+ inner : Element | null = null ;
177+
178+ render ( ) {
179+ return html `
168180 < style >
169181 x-inner1 {
170182 --border : 2px solid red;
171183 }
172184 </ style >
173185 < x-inner1 > </ x-inner1 > ` ;
174- }
175-
176- firstUpdated ( ) {
177- this . inner = this . shadowRoot ! . querySelector ( 'x-inner1' ) ;
178- }
179- } ) ;
180- const name2 = generateElementName ( ) ;
181- customElements . define ( name2 , class extends LitElement {
182-
183- render ( ) { return html `
186+ }
187+
188+ firstUpdated ( ) {
189+ this . inner = this . shadowRoot ! . querySelector ( 'x-inner1' ) ;
190+ }
191+ } ) ;
192+ const name2 = generateElementName ( ) ;
193+ customElements . define ( name2 , class extends LitElement {
194+ render ( ) {
195+ return html `
184196 < style >
185197 x-inner1 {
186198 --border : 8px solid red;
187199 }
188200 </ style > ` ;
189- }
190-
191- } ) ;
192- const el = document . createElement ( name1 ) as LitElement ;
193- const el2 = document . createElement ( name2 ) ;
194- container . appendChild ( el ) ;
195- container . appendChild ( el2 ) ;
196- let div : Element | null ;
197-
198- // Workaround for Safari 9 Promise timing bugs.
199- await el . updateComplete ;
200-
201- await nextFrame ( ) ;
202- const inner = el . shadowRoot ! . querySelector ( 'x-inner1' ) ;
203- div = inner ! . shadowRoot ! . querySelector ( 'div' ) ;
204- assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) , '2px' ) ;
205- el2 ! . shadowRoot ! . appendChild ( inner ! ) ;
206-
207- // Workaround for Safari 9 Promise timing bugs.
208- await el . updateComplete ;
209-
210- await nextFrame ( ) ;
211- assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) , '8px' ) ;
212- } ) ;
201+ }
202+ } ) ;
203+ const el = document . createElement ( name1 ) as LitElement ;
204+ const el2 = document . createElement ( name2 ) ;
205+ container . appendChild ( el ) ;
206+ container . appendChild ( el2 ) ;
207+ let div : Element | null ;
208+
209+ // Workaround for Safari 9 Promise timing bugs.
210+ await el . updateComplete ;
211+
212+ await nextFrame ( ) ;
213+ const inner = el . shadowRoot ! . querySelector ( 'x-inner1' ) ;
214+ div = inner ! . shadowRoot ! . querySelector ( 'div' ) ;
215+ assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) ,
216+ '2px' ) ;
217+ el2 ! . shadowRoot ! . appendChild ( inner ! ) ;
218+
219+ // Workaround for Safari 9 Promise timing bugs.
220+ await el . updateComplete ;
221+
222+ await nextFrame ( ) ;
223+ assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) ,
224+ '8px' ) ;
225+ } ) ;
213226
214227 test ( '@apply renders in nested elements' , async ( ) => {
215228 customElements . define ( 'x-inner2' , class extends LitElement {
216- render ( ) { return html `
229+ render ( ) {
230+ return html `
217231 < style >
218232 div {
219233 @apply --bag;
@@ -225,7 +239,8 @@ suite('Styling', () => {
225239 const name = generateElementName ( ) ;
226240 class E extends LitElement {
227241 inner : LitElement | null = null ;
228- render ( ) { return html `
242+ render ( ) {
243+ return html `
229244 < style >
230245 x-inner2 {
231246 --bag : {
@@ -248,14 +263,14 @@ suite('Styling', () => {
248263 await el . updateComplete && await el . inner ! . updateComplete ;
249264
250265 await nextFrame ( ) ;
251- const div = el . shadowRoot ! . querySelector ( 'x-inner2' ) ! . shadowRoot ! . querySelector ( 'div' ) ;
252- assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) , '10px' ) ;
266+ const div = el . shadowRoot ! . querySelector (
267+ 'x-inner2' ) ! . shadowRoot ! . querySelector ( 'div' ) ;
268+ assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) ,
269+ '10px' ) ;
253270 } ) ;
254-
255271} ) ;
256272
257273suite ( 'ShadyDOM' , ( ) => {
258-
259274 let container : HTMLElement ;
260275
261276 setup ( function ( ) {
@@ -273,28 +288,31 @@ suite('ShadyDOM', () => {
273288 }
274289 } ) ;
275290
276- test ( 'properties in styles render with initial value and cannot be changed' , async ( ) => {
277- let border = `6px solid blue` ;
278- const name = generateElementName ( ) ;
279- customElements . define ( name , class extends LitElement {
280- render ( ) { return html `
291+ test ( 'properties in styles render with initial value and cannot be changed' ,
292+ async ( ) => {
293+ let border = `6px solid blue` ;
294+ const name = generateElementName ( ) ;
295+ customElements . define ( name , class extends LitElement {
296+ render ( ) {
297+ return html `
281298 < style >
282299 div {
283300 border : ${ border } ;
284301 }
285302 </ style >
286303 < div > Testing...</ div > ` ;
287- }
288- } ) ;
289- const el = document . createElement ( name ) as LitElement ;
290- container . appendChild ( el ) ;
291- await el . updateComplete ;
292- const div = el . shadowRoot ! . querySelector ( 'div' ) ;
293- assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) , '6px' ) ;
294- border = `4px solid orange` ;
295- el . requestUpdate ( ) ;
296- await el . updateComplete ;
297- assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) , '6px' ) ;
298- } ) ;
299-
304+ }
305+ } ) ;
306+ const el = document . createElement ( name ) as LitElement ;
307+ container . appendChild ( el ) ;
308+ await el . updateComplete ;
309+ const div = el . shadowRoot ! . querySelector ( 'div' ) ;
310+ assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) ,
311+ '6px' ) ;
312+ border = `4px solid orange` ;
313+ el . requestUpdate ( ) ;
314+ await el . updateComplete ;
315+ assert . equal ( getComputedStyleValue ( div ! , 'border-top-width' ) . trim ( ) ,
316+ '6px' ) ;
317+ } ) ;
300318} ) ;
0 commit comments