Skip to content

Commit 50dffb0

Browse files
committed
test(wtr): clear <head> and clear global stylesheets when needed
1 parent 6ce708a commit 50dffb0

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

packages/@lwc/integration-karma/test/mixed-shadow-mode/synthetic-behavior/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import GrandparentResetParentAnyChildReset from 'x/grandparentResetParentAnyChil
1515
import GrandparentResetParentResetChildAny from 'x/grandparentResetParentResetChildAny';
1616
import GrandparentResetParentResetChildReset from 'x/grandparentResetParentResetChildReset';
1717

18+
afterEach(() => {
19+
window.__lwcResetGlobalStylesheets();
20+
});
21+
1822
describe.skipIf(process.env.NATIVE_SHADOW)('synthetic behavior', () => {
1923
const scenarios = [
2024
{

packages/@lwc/integration-karma/test/rendering/style-specificity-important/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { createElement } from 'lwc';
22
import Component from 'x/component';
33

4+
afterEach(() => {
5+
window.__lwcResetGlobalStylesheets();
6+
});
7+
48
describe('important styling and style override', () => {
59
it('should render !important styles correctly', async () => {
610
const elm = createElement('x-component', { is: Component });

packages/@lwc/integration-karma/test/shadow-dom/stylesheet/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import Parent from 'x/parent';
44
import Host from 'x/host';
55
import MultiTemplates from 'x/multiTemplates';
66

7+
afterEach(() => {
8+
window.__lwcResetGlobalStylesheets();
9+
});
10+
711
describe('shadow encapsulation', () => {
812
it('should not style children elements', () => {
913
const elm = createElement('x-parent', { is: Parent });

packages/@lwc/integration-karma/test/synthetic-shadow/dom-manual-sharing-nodes/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { createElement } from 'lwc';
33
import Unstyled from 'x/unstyled';
44
import Styled from 'x/styled';
55

6+
afterEach(() => {
7+
window.__lwcResetGlobalStylesheets();
8+
});
9+
610
describe('dom manual sharing nodes', () => {
711
it('has correct styles when sharing nodes from styled to unstyled component', () => {
812
const unstyled = createElement('x-unstyled', { is: Unstyled });

packages/@lwc/integration-karma/test/template/directive-lwc-dom-manual/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ function waitForStyleToBeApplied() {
88
return Promise.resolve();
99
}
1010

11+
afterEach(() => {
12+
window.__lwcResetGlobalStylesheets();
13+
});
14+
1115
describe('dom mutation without the lwc:dom="manual" directive', () => {
1216
function testErrorOnDomMutation(method, fn) {
1317
it(`should log a warning when calling ${method} on an element without the lwc:dom="manual" directive only in synthetic mode`, () => {

packages/@lwc/integration-karma/test/template/directive-lwc-inner-html/index.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ let originalSanitizeHtmlContent;
77

88
beforeAll(() => {
99
originalSanitizeHtmlContent = getHooks().sanitizeHtmlContent;
10-
setHooks({
11-
sanitizeHtmlContent: (content) => content,
12-
});
10+
setHooks({ sanitizeHtmlContent: (content) => content });
1311
});
1412

1513
afterAll(() => {
16-
setHooks({
17-
sanitizeHtmlContent: originalSanitizeHtmlContent,
18-
});
14+
setHooks({ sanitizeHtmlContent: originalSanitizeHtmlContent });
15+
});
16+
17+
afterEach(() => {
18+
window.__lwcResetGlobalStylesheets();
1919
});
2020

21-
it('renders the content as HTML', () => {
21+
it('renders the content as HTML', async () => {
2222
const elm = createElement('x-inner-html', { is: XInnerHtml });
2323
elm.content = 'Hello <b>World</b>';
2424
document.body.appendChild(elm);

packages/@lwc/integration-not-karma/helpers/setup.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ hijackGlobal('afterEach', (afterEach) => {
106106
// FIXME: Boost test speed by moving this to only files that need it
107107
// Ensure the DOM is in a clean state
108108
document.body.replaceChildren();
109+
document.head.replaceChildren();
109110
});
110111
});
111112

0 commit comments

Comments
 (0)