@@ -27,21 +27,34 @@ describe("stringifyStyleMap", () => {
2727 ) ;
2828 } ) ;
2929
30- it ( "doesn't change CSS-selector string" , ( ) => {
30+ it ( "makes CSS-rules with CSS-selector string and CSS-properties string" , ( ) => {
3131 const expected =
32- "header{color:teal;} .className{color:teal;} body ul > li {color:teal;}" ;
32+ "header{color:teal;}.className{color:teal;}#root {color:teal;}" ;
3333 const actual = stringifyStyleMap ( {
3434 header : cssProperties ,
3535 ".className" : cssProperties ,
36- "body ul > li " : cssProperties ,
36+ "#root " : cssProperties ,
3737 } ) ;
3838
3939 expect ( actual ) . toBe ( expected ) ;
4040 } ) ;
4141
42- // TODO: add reducing feature to stringifyStyleMap
43- it ( "doesn't reduce styles for empty cssProperties" , ( ) => {
44- const expected = "header{color:teal;} main{} footer{color:teal;}" ;
42+ it ( "trims CSS-selector string properly" , ( ) => {
43+ const expected =
44+ ".className{color:teal;}#root div h1{color:teal;}#root>ul li{color:teal;}*>p+ul li{color:teal;}div~p.className{color:teal;}" ;
45+ const actual = stringifyStyleMap ( {
46+ " .className " : cssProperties ,
47+ "#root div h1" : cssProperties ,
48+ "#root > ul li" : cssProperties ,
49+ "* > p+ ul li" : cssProperties ,
50+ "div ~p.className" : cssProperties ,
51+ } ) ;
52+
53+ expect ( actual ) . toBe ( expected ) ;
54+ } ) ;
55+
56+ it ( "reduces styles for empty cssProperties" , ( ) => {
57+ const expected = "header{color:teal;}footer{color:teal;}" ;
4558 const actual = stringifyStyleMap ( {
4659 header : cssProperties ,
4760 main : { } ,
@@ -50,4 +63,18 @@ describe("stringifyStyleMap", () => {
5063
5164 expect ( actual ) . toBe ( expected ) ;
5265 } ) ;
66+
67+ it ( "injects the '!important' statement for each style property" , ( ) => {
68+ const expected =
69+ "#root{color:teal!important;}.footer{color:teal!important;}" ;
70+ const actual = stringifyStyleMap (
71+ {
72+ "#root" : cssProperties ,
73+ ".footer" : cssProperties ,
74+ } ,
75+ true
76+ ) ;
77+
78+ expect ( actual ) . toBe ( expected ) ;
79+ } ) ;
5380} ) ;
0 commit comments