Skip to content

Commit c172c04

Browse files
committed
restructure tests a bit
1 parent 2aa7ec7 commit c172c04

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/test/lit-element_styling_test.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -898,23 +898,22 @@ suite('Static get styles', () => {
898898
document.body.removeChild(element);
899899
});
900900

901-
// Test this in Shadow DOM without `adoptedStyleSheets` only since it's easily
902-
// detectable in that case. Look explicitly for no ShadyCSS.
903901
const testAdoptedStyleSheets =
904-
(typeof ShadowRoot === 'function') &&
905-
('adoptedStyleSheets' in window.ShadowRoot.prototype);
902+
(window.ShadowRoot) &&
903+
('replace' in CSSStyleSheet.prototype);
906904
(testAdoptedStyleSheets ? test : test.skip)(
907905
'Can return CSSStyleSheet where adoptedStyleSheets are natively supported',
908906
async () => {
909907
const sheet = new CSSStyleSheet();
910908
sheet.replaceSync('div { border: 4px solid red; }');
909+
const normal = css`span { border: 4px solid blue; }`;
911910

912911
const base = generateElementName();
913912
customElements.define(base, class extends LitElement {
914-
static styles = sheet;
913+
static styles = [sheet, normal];
915914

916915
render() {
917-
return htmlWithStyles`<div></div>`;
916+
return htmlWithStyles`<div></div><span></span>`;
918917
}
919918
});
920919

@@ -926,37 +925,42 @@ suite('Static get styles', () => {
926925
getComputedStyle(div).getPropertyValue('border-top-width').trim(),
927926
'4px');
928927

928+
const span = el.shadowRoot!.querySelector('span')!;
929+
assert.equal(
930+
getComputedStyle(span).getPropertyValue('border-top-width').trim(),
931+
'4px');
932+
929933
// When the WC polyfills are included, calling .replaceSync is a noop to
930934
// our styles as they're already flattened (so expect 4px). Otherwise,
931935
// look for the updated value.
932-
const flattenDueToPolyfill = (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow);
933-
const expectedValue = flattenDueToPolyfill ? '4px' : '2px';
936+
const usesAdoptedStyleSheet = (window.ShadyCSS === undefined || window.ShadyCSS.nativeShadow);
937+
const expectedValue = usesAdoptedStyleSheet ? '2px' : '4px';
934938
sheet.replaceSync('div { border: 2px solid red; }');
935939

936940
assert.equal(
937941
getComputedStyle(div).getPropertyValue('border-top-width').trim(),
938942
expectedValue);
939943
});
940944

941-
// Test that when ShadyCSS is enabled with native support for
942-
// adoptedStyleSheets, we can return a CSSStyleSheet that will be flattened
945+
// Test that when ShadyCSS is enabled (while still having native support for
946+
// adoptedStyleSheets), we can return a CSSStyleSheet that will be flattened
943947
// and play nice with others.
944-
const testShadyCSSWithAdoptedStyleSheetSupport = (typeof ShadowRoot === 'function') &&
945-
('adoptedStyleSheets' in window.ShadowRoot.prototype) &&
948+
const testShadyCSSWithAdoptedStyleSheetSupport =
949+
(window.ShadowRoot) &&
950+
('replace' in CSSStyleSheet.prototype) &&
946951
(window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow);
947952
(testShadyCSSWithAdoptedStyleSheetSupport ? test : test.skip)(
948953
'CSSStyleSheet is flattened where ShadyCSS is enabled yet adoptedStyleSheets are supported',
949954
async () => {
950955
const sheet = new CSSStyleSheet();
951956
sheet.replaceSync('div { border: 4px solid red; }');
952-
const normal = css`span { border: 4px solid blue; }`;
953957

954958
const base = generateElementName();
955959
customElements.define(base, class extends LitElement {
956-
static styles = [sheet, normal];
960+
static styles = sheet;
957961

958962
render() {
959-
return htmlWithStyles`<div></div><span></span>`;
963+
return htmlWithStyles`<div></div>`;
960964
}
961965
});
962966

@@ -969,11 +973,6 @@ suite('Static get styles', () => {
969973
getComputedStyle(div).getPropertyValue('border-top-width').trim(),
970974
'4px');
971975

972-
const span = el.shadowRoot!.querySelector('span')!;
973-
assert.equal(
974-
getComputedStyle(span).getPropertyValue('border-top-width').trim(),
975-
'4px');
976-
977976
// CSSStyleSheet update should fail, as the styles will be flattened.
978977
sheet.replaceSync('div { border: 2px solid red; }');
979978
assert.equal(

0 commit comments

Comments
 (0)