@@ -280,4 +280,49 @@ describe('utils', () => {
280280 expect ( out3 ) . toEqual ( '[data-aa\\:other] { color: red; }' ) ;
281281 } ) ;
282282 } ) ;
283+
284+ describe ( 'stringifyStylesheet' , ( ) => {
285+ it ( 'returns null if rules are missing' , ( ) => {
286+ const mockSheet = {
287+ rules : null ,
288+ cssRules : null ,
289+ } as unknown as CSSStyleSheet ;
290+ expect ( stringifyStylesheet ( mockSheet ) ) . toBeNull ( ) ;
291+ } ) ;
292+
293+ it ( 'stringifies rules using .cssRules if .rules is missing' , ( ) => {
294+ const mockRule1 = { cssText : 'div { margin: 0; }' } as CSSRule ;
295+ const mockSheet = {
296+ cssRules : [ mockRule1 ] ,
297+ href : 'https://example.com/main.css' ,
298+ } as unknown as CSSStyleSheet ;
299+ expect ( stringifyStylesheet ( mockSheet ) ) . toBe ( 'div { margin: 0; }' ) ;
300+ } ) ;
301+
302+ it ( 'uses ownerNode.baseURI for inline styles' , ( ) => {
303+ const mockFontFaceRule = {
304+ cssText : `
305+ @font-face {
306+ font-family: 'MockFont';
307+ src: url('../fonts/mockfont.woff2') format('woff2');
308+ font-weight: normal;
309+ font-style: normal;
310+ }
311+ ` ,
312+ } as CSSRule ;
313+ const mockOwnerNode = {
314+ baseURI : 'https://example.com/fonts/' ,
315+ } as unknown as Node ;
316+ const mockSheet = {
317+ cssRules : [ mockFontFaceRule ] ,
318+ href : null ,
319+ ownerNode : mockOwnerNode ,
320+ } as unknown as CSSStyleSheet ;
321+ expect (
322+ stringifyStylesheet ( mockSheet ) ?. replace ( / \s + / g, ' ' ) . trim ( ) ,
323+ ) . toEqual (
324+ "@font-face { font-family: 'MockFont'; src: url('https://example.com/fonts/mockfont.woff2') format('woff2'); font-weight: normal; font-style: normal; }" ,
325+ ) ;
326+ } ) ;
327+ } ) ;
283328} ) ;
0 commit comments