Skip to content

Commit c4640ef

Browse files
committed
test: refactor test, remove test covered in #2859
1 parent c9e7e01 commit c4640ef

File tree

9 files changed

+44
-94
lines changed

9 files changed

+44
-94
lines changed

packages/integration-karma/test/static-content/index.spec.js

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,48 @@
1-
import { createElement, setFeatureFlagForTest } from 'lwc';
2-
import Container from './x/container/container';
1+
import { createElement } from 'lwc';
32
import MultipleStyles from './x/multipleStyles/multipleStyles';
43
import SvgNs from './x/svgNs/svgNs';
54

6-
if (!process.env.NATIVE_SHADOW && !process.env.COMPAT) {
7-
/* compat will have the token when rendering in native*/ describe('Mixed mode for static content', () => {
8-
beforeEach(() => {
9-
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
10-
});
11-
afterEach(() => {
12-
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
13-
});
14-
15-
['native', 'synthetic'].forEach((firstRenderMode) => {
16-
it(`should set the tokens for synthetic shadow when it renders first in ${firstRenderMode}`, () => {
17-
const elm = createElement('x-container', { is: Container });
18-
elm.syntheticFirst = firstRenderMode === 'synthetic';
19-
document.body.appendChild(elm);
5+
describe('static content when stylesheets change', () => {
6+
it('should reflect correct token for scoped styles', () => {
7+
const elm = createElement('x-container', { is: MultipleStyles });
208

21-
const syntheticMode = elm.shadowRoot
22-
.querySelector('x-component')
23-
.shadowRoot.querySelector('div');
24-
const nativeMode = elm.shadowRoot
25-
.querySelector('x-native')
26-
.shadowRoot.querySelector('x-component')
27-
.shadowRoot.querySelector('div');
9+
const stylesheetsWarning =
10+
/Dynamically setting the "stylesheets" property on a template function is deprecated and may be removed in a future version of LWC./;
2811

29-
expect(syntheticMode.hasAttribute('x-component_component')).toBe(true);
30-
expect(nativeMode.hasAttribute('x-component_component')).toBe(false);
12+
expect(() => {
13+
elm.updateTemplate({
14+
name: 'a',
15+
useScopedCss: false,
3116
});
32-
});
33-
});
34-
}
17+
}).toLogErrorDev(stylesheetsWarning);
3518

36-
describe('static content when stylesheets change', () => {
37-
it('should reflect correct token for scoped styles', () => {
38-
const elm = createElement('x-container', { is: MultipleStyles });
3919
document.body.appendChild(elm);
4020

4121
expect(elm.shadowRoot.querySelector('div').getAttribute('class')).toBe('foo');
4222

4323
// atm, we need to switch templates.
44-
elm.tpl = 'b';
45-
elm.useScopeCss = true;
24+
expect(() => {
25+
elm.updateTemplate({
26+
name: 'b',
27+
useScopedCss: true,
28+
});
29+
}).toLogErrorDev(stylesheetsWarning);
4630

4731
return Promise.resolve()
4832
.then(() => {
49-
expect(elm.shadowRoot.querySelector('div').getAttribute('class')).toBe(
50-
'foo x-multipleStyles_b'
51-
);
52-
elm.tpl = 'a';
53-
elm.useScopeCss = false;
33+
const classList = Array.from(elm.shadowRoot.querySelector('div').classList).sort();
34+
expect(classList).toEqual(['foo', 'x-multipleStyles_b']);
35+
36+
expect(() => {
37+
elm.updateTemplate({
38+
name: 'a',
39+
useScopedCss: false,
40+
});
41+
}).toLogErrorDev(stylesheetsWarning);
5442
})
5543
.then(() => {
56-
expect(elm.shadowRoot.querySelector('div').getAttribute('class')).toBe('foo');
44+
const classList = Array.from(elm.shadowRoot.querySelector('div').classList).sort();
45+
expect(classList).toEqual(['foo']);
5746
});
5847
});
5948
});

packages/integration-karma/test/static-content/x/component/component.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/integration-karma/test/static-content/x/component/component.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/integration-karma/test/static-content/x/component/component.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/integration-karma/test/static-content/x/container/container.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/integration-karma/test/static-content/x/container/container.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import { LightningElement, api } from 'lwc';
2-
import aTpl from './a.html';
3-
import bTpl from './b.html';
2+
import aTemplate from './a.html';
3+
import bTemplate from './b.html';
44
import aCss from './a.css';
55
import bCss from './b.scoped.css?scoped=true';
66

7-
const tplMap = {
8-
a: aTpl,
9-
b: bTpl,
7+
const templateMap = {
8+
a: aTemplate,
9+
b: bTemplate,
1010
};
1111
export default class Container extends LightningElement {
12-
@api tpl = 'a';
13-
@api useScopeCss = false;
12+
_template = aTemplate;
1413

15-
render() {
16-
const template = tplMap[this.tpl];
14+
@api
15+
updateTemplate({ name, useScopedCss }) {
16+
const template = templateMap[name];
17+
18+
// TODO [#2826]: freeze the template object and stop supporting setting the stylesheets
19+
template.stylesheets = useScopedCss ? [...aCss, ...bCss] : [...aCss];
1720

18-
template.stylesheets = this.useScopeCss ? [...aCss, ...bCss] : [...aCss];
21+
this._template = template;
22+
}
1923

20-
return template;
24+
render() {
25+
return this._template;
2126
}
2227
}

packages/integration-karma/test/static-content/x/native/native.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/integration-karma/test/static-content/x/native/native.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)