Skip to content

Commit 89de2f9

Browse files
committed
test(theme): add more tests for injectCSS
1 parent 590647a commit 89de2f9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

core/src/utils/theme.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { newSpecPage } from '@stencil/core/testing';
2+
3+
import { CardContent } from '../components/card-content/card-content';
4+
import { Chip } from '../components/chip/chip';
5+
16
import { generateComponentThemeCSS, generateCSSVars, generateGlobalThemeCSS, injectCSS } from './theme';
27

38
describe('generateCSSVars', () => {
@@ -72,6 +77,36 @@ describe('injectCSS', () => {
7277
injectCSS(css);
7378
expect(document.head.innerHTML).toContain(`<style>${css}</style>`);
7479
});
80+
81+
it('should inject CSS into an element', async () => {
82+
const page = await newSpecPage({
83+
components: [CardContent],
84+
html: '<ion-card-content></ion-card-content>',
85+
});
86+
87+
const target = page.body.querySelector('ion-card-content')!;
88+
89+
const css = ':host { background-color: red; }';
90+
injectCSS(css, target);
91+
92+
expect(target.innerHTML).toContain(`<style>${css}</style>`);
93+
});
94+
95+
it('should inject CSS into an element with a shadow root', async () => {
96+
const page = await newSpecPage({
97+
components: [Chip],
98+
html: '<ion-chip></ion-chip>',
99+
});
100+
101+
const target = page.body.querySelector('ion-chip')!;
102+
const shadowRoot = target.shadowRoot;
103+
expect(shadowRoot).toBeTruthy();
104+
105+
const css = ':host { background-color: red; }';
106+
injectCSS(css, shadowRoot!);
107+
108+
expect(shadowRoot!.innerHTML).toContain(`<style>${css}</style>`);
109+
});
75110
});
76111

77112
describe('generateGlobalThemeCSS', () => {

0 commit comments

Comments
 (0)