@@ -391,4 +391,231 @@ describe('CSSNode', () => {
391391 expect ( media . has_declarations ) . toBe ( false )
392392 } )
393393 } )
394+
395+ describe ( 'type_name property' , ( ) => {
396+ test ( 'should return stylesheet for root node' , ( ) => {
397+ const source = 'body { color: red; }'
398+ const parser = new Parser ( source )
399+ const root = parser . parse ( )
400+
401+ expect ( root . type_name ) . toBe ( 'stylesheet' )
402+ } )
403+
404+ test ( 'should return style_rule for style rules' , ( ) => {
405+ const source = 'body { color: red; }'
406+ const parser = new Parser ( source )
407+ const root = parser . parse ( )
408+ const rule = root . first_child !
409+
410+ expect ( rule . type_name ) . toBe ( 'rule' )
411+ } )
412+
413+ test ( 'should return declaration for declarations' , ( ) => {
414+ const source = 'body { color: red; }'
415+ const parser = new Parser ( source )
416+ const root = parser . parse ( )
417+ const rule = root . first_child !
418+ const block = rule . block !
419+ const decl = block . first_child !
420+
421+ expect ( decl . type_name ) . toBe ( 'declaration' )
422+ } )
423+
424+ test ( 'should return at_rule for at-rules' , ( ) => {
425+ const source = '@media screen { body { color: red; } }'
426+ const parser = new Parser ( source )
427+ const root = parser . parse ( )
428+ const media = root . first_child !
429+
430+ expect ( media . type_name ) . toBe ( 'atrule' )
431+ } )
432+
433+ test ( 'should return selector_list for selector lists' , ( ) => {
434+ const source = 'body { color: red; }'
435+ const parser = new Parser ( source )
436+ const root = parser . parse ( )
437+ const rule = root . first_child !
438+ const selectorList = rule . first_child !
439+
440+ expect ( selectorList . type_name ) . toBe ( 'selectorlist' )
441+ } )
442+
443+ test ( 'should return selector_type for type selectors' , ( ) => {
444+ const source = 'div { color: red; }'
445+ const parser = new Parser ( source )
446+ const root = parser . parse ( )
447+ const rule = root . first_child !
448+ const selectorList = rule . first_child !
449+ const selector = selectorList . first_child !
450+ const typeSelector = selector . first_child !
451+
452+ expect ( typeSelector . type_name ) . toBe ( 'type-selector' )
453+ } )
454+
455+ test ( 'should return selector_class for class selectors' , ( ) => {
456+ const source = '.foo { color: red; }'
457+ const parser = new Parser ( source )
458+ const root = parser . parse ( )
459+ const rule = root . first_child !
460+ const selectorList = rule . first_child !
461+ const selector = selectorList . first_child !
462+ const classSelector = selector . first_child !
463+
464+ expect ( classSelector . type_name ) . toBe ( 'class-selector' )
465+ } )
466+
467+ test ( 'should return selector_id for ID selectors' , ( ) => {
468+ const source = '#bar { color: red; }'
469+ const parser = new Parser ( source )
470+ const root = parser . parse ( )
471+ const rule = root . first_child !
472+ const selectorList = rule . first_child !
473+ const selector = selectorList . first_child !
474+ const idSelector = selector . first_child !
475+
476+ expect ( idSelector . type_name ) . toBe ( 'id-selector' )
477+ } )
478+
479+ test ( 'should return selector_universal for universal selectors' , ( ) => {
480+ const source = '* { color: red; }'
481+ const parser = new Parser ( source )
482+ const root = parser . parse ( )
483+ const rule = root . first_child !
484+ const selectorList = rule . first_child !
485+ const selector = selectorList . first_child !
486+ const universalSelector = selector . first_child !
487+
488+ expect ( universalSelector . type_name ) . toBe ( 'universal-selector' )
489+ } )
490+
491+ test ( 'should return selector_attribute for attribute selectors' , ( ) => {
492+ const source = '[href] { color: red; }'
493+ const parser = new Parser ( source )
494+ const root = parser . parse ( )
495+ const rule = root . first_child !
496+ const selectorList = rule . first_child !
497+ const selector = selectorList . first_child !
498+ const attrSelector = selector . first_child !
499+
500+ expect ( attrSelector . type_name ) . toBe ( 'attribute-selector' )
501+ } )
502+
503+ test ( 'should return selector_pseudo_class for pseudo-class selectors' , ( ) => {
504+ const source = ':hover { color: red; }'
505+ const parser = new Parser ( source )
506+ const root = parser . parse ( )
507+ const rule = root . first_child !
508+ const selectorList = rule . first_child !
509+ const selector = selectorList . first_child !
510+ const pseudoClass = selector . first_child !
511+
512+ expect ( pseudoClass . type_name ) . toBe ( 'pseudoclass-selector' )
513+ } )
514+
515+ test ( 'should return selector_pseudo_element for pseudo-element selectors' , ( ) => {
516+ const source = '::before { color: red; }'
517+ const parser = new Parser ( source )
518+ const root = parser . parse ( )
519+ const rule = root . first_child !
520+ const selectorList = rule . first_child !
521+ const selector = selectorList . first_child !
522+ const pseudoElement = selector . first_child !
523+
524+ expect ( pseudoElement . type_name ) . toBe ( 'pseudoelement-selector' )
525+ } )
526+
527+ test ( 'should return selector_combinator for combinators' , ( ) => {
528+ const source = 'div > span { color: red; }'
529+ const parser = new Parser ( source )
530+ const root = parser . parse ( )
531+ const rule = root . first_child !
532+ const selectorList = rule . first_child !
533+ const selector = selectorList . first_child !
534+ const combinator = selector . first_child ! . next_sibling !
535+
536+ expect ( combinator . type_name ) . toBe ( 'selector-combinator' )
537+ } )
538+
539+ test ( 'should return value_keyword for keyword values' , ( ) => {
540+ const source = 'body { color: red; }'
541+ const parser = new Parser ( source )
542+ const root = parser . parse ( )
543+ const rule = root . first_child !
544+ const block = rule . block !
545+ const decl = block . first_child !
546+ const value = decl . first_child !
547+
548+ expect ( value . type_name ) . toBe ( 'keyword' )
549+ } )
550+
551+ test ( 'should return value_number for numeric values' , ( ) => {
552+ const source = 'body { opacity: 0.5; }'
553+ const parser = new Parser ( source )
554+ const root = parser . parse ( )
555+ const rule = root . first_child !
556+ const block = rule . block !
557+ const decl = block . first_child !
558+ const value = decl . first_child !
559+
560+ expect ( value . type_name ) . toBe ( 'number' )
561+ } )
562+
563+ test ( 'should return value_dimension for dimension values' , ( ) => {
564+ const source = 'body { width: 100px; }'
565+ const parser = new Parser ( source )
566+ const root = parser . parse ( )
567+ const rule = root . first_child !
568+ const block = rule . block !
569+ const decl = block . first_child !
570+ const value = decl . first_child !
571+
572+ expect ( value . type_name ) . toBe ( 'dimension' )
573+ } )
574+
575+ test ( 'should return value_string for string values' , ( ) => {
576+ const source = 'body { content: "hello"; }'
577+ const parser = new Parser ( source )
578+ const root = parser . parse ( )
579+ const rule = root . first_child !
580+ const block = rule . block !
581+ const decl = block . first_child !
582+ const value = decl . first_child !
583+
584+ expect ( value . type_name ) . toBe ( 'string' )
585+ } )
586+
587+ test ( 'should return value_color for color values' , ( ) => {
588+ const source = 'body { color: #ff0000; }'
589+ const parser = new Parser ( source )
590+ const root = parser . parse ( )
591+ const rule = root . first_child !
592+ const block = rule . block !
593+ const decl = block . first_child !
594+ const value = decl . first_child !
595+
596+ expect ( value . type_name ) . toBe ( 'color' )
597+ } )
598+
599+ test ( 'should return value_function for function values' , ( ) => {
600+ const source = 'body { width: calc(100% - 20px); }'
601+ const parser = new Parser ( source )
602+ const root = parser . parse ( )
603+ const rule = root . first_child !
604+ const block = rule . block !
605+ const decl = block . first_child !
606+ const value = decl . first_child !
607+
608+ expect ( value . type_name ) . toBe ( 'function' )
609+ } )
610+
611+ test ( 'should return prelude_media_query for media query preludes' , ( ) => {
612+ const source = '@media screen and (min-width: 768px) { body { color: red; } }'
613+ const parser = new Parser ( source )
614+ const root = parser . parse ( )
615+ const media = root . first_child !
616+ const prelude = media . first_child !
617+
618+ expect ( prelude . type_name ) . toBe ( 'media-query' )
619+ } )
620+ } )
394621} )
0 commit comments