|
| 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 | + |
1 | 6 | import { generateComponentThemeCSS, generateCSSVars, generateGlobalThemeCSS, injectCSS } from './theme'; |
2 | 7 |
|
3 | 8 | describe('generateCSSVars', () => { |
@@ -72,6 +77,36 @@ describe('injectCSS', () => { |
72 | 77 | injectCSS(css); |
73 | 78 | expect(document.head.innerHTML).toContain(`<style>${css}</style>`); |
74 | 79 | }); |
| 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 | + }); |
75 | 110 | }); |
76 | 111 |
|
77 | 112 | describe('generateGlobalThemeCSS', () => { |
|
0 commit comments