1+ import { render , screen } from "@testing-library/react-native" ;
2+ import { View } from "react-native-css/components" ;
3+ import { registerCSS , testID } from "react-native-css/jest" ;
4+
15import { compile } from "../compiler" ;
26
37test ( "@prop single" , ( ) => {
4- const compiled = compile ( `
5- .test {
8+ const compiled = registerCSS ( `
9+ .my-class {
610 color: red;
711 background-color: blue;
812 @prop background-color: myBackgroundColor;
@@ -12,14 +16,14 @@ test("@prop single", () => {
1216 expect ( compiled . stylesheet ( ) ) . toStrictEqual ( {
1317 s : [
1418 [
15- "test " ,
19+ "my-class " ,
1620 [
1721 {
1822 d : [
1923 {
2024 color : "#f00" ,
21- myBackgroundColor : "#00f" ,
2225 } ,
26+ [ "#00f" , [ "myBackgroundColor" ] ] ,
2327 ] ,
2428 v : [ [ "__rn-css-color" , "#f00" ] ] ,
2529 s : [ 1 , 1 ] ,
@@ -28,6 +32,18 @@ test("@prop single", () => {
2832 ] ,
2933 ] ,
3034 } ) ;
35+
36+ render ( < View testID = { testID } className = "my-class" /> ) ;
37+ const component = screen . getByTestId ( testID ) ;
38+
39+ expect ( component . props ) . toStrictEqual ( {
40+ testID,
41+ children : undefined ,
42+ myBackgroundColor : "#00f" ,
43+ style : {
44+ color : "#f00" ,
45+ } ,
46+ } ) ;
3147} ) ;
3248
3349test ( "@prop single, nested value" , ( ) => {
@@ -60,12 +76,12 @@ test("@prop single, nested value", () => {
6076 } ) ;
6177} ) ;
6278
63- test ( "@prop single, top level " , ( ) => {
79+ test ( "@prop single, on target " , ( ) => {
6480 const compiled = compile ( `
6581 .test {
6682 color: red;
6783 background-color: blue;
68- @prop background-color: ^ myBackgroundColor;
84+ @prop background-color: *. myBackgroundColor;
6985 }
7086 ` ) ;
7187
@@ -78,8 +94,8 @@ test("@prop single, top level", () => {
7894 d : [
7995 {
8096 color : "#f00" ,
97+ myBackgroundColor : "#00f" ,
8198 } ,
82- [ "#00f" , [ "^" , "myBackgroundColor" ] ] ,
8399 ] ,
84100 v : [ [ "__rn-css-color" , "#f00" ] ] ,
85101 s : [ 1 , 1 ] ,
@@ -90,26 +106,26 @@ test("@prop single, top level", () => {
90106 } ) ;
91107} ) ;
92108
93- test ( "@prop single, top level, nested" , ( ) => {
94- const compiled = compile ( `
95- .test {
109+ test ( "@prop single, nested" , ( ) => {
110+ const compiled = registerCSS ( `
111+ .my-class {
96112 color: red;
97113 background-color: blue;
98- @prop background-color: ^ myBackgroundColor.test;
114+ @prop background-color: *. myBackgroundColor.test;
99115 }
100116 ` ) ;
101117
102118 expect ( compiled . stylesheet ( ) ) . toStrictEqual ( {
103119 s : [
104120 [
105- "test " ,
121+ "my-class " ,
106122 [
107123 {
108124 d : [
109125 {
110126 color : "#f00" ,
111127 } ,
112- [ "#00f" , [ "^ " , "myBackgroundColor" , "test" ] ] ,
128+ [ "#00f" , [ "* " , "myBackgroundColor" , "test" ] ] ,
113129 ] ,
114130 v : [ [ "__rn-css-color" , "#f00" ] ] ,
115131 s : [ 1 , 1 ] ,
@@ -118,14 +134,24 @@ test("@prop single, top level, nested", () => {
118134 ] ,
119135 ] ,
120136 } ) ;
137+
138+ render ( < View testID = { testID } className = "my-class" /> ) ;
139+ const component = screen . getByTestId ( testID ) ;
140+
141+ expect ( component . props . style ) . toStrictEqual ( {
142+ color : "#f00" ,
143+ myBackgroundColor : {
144+ test : "#00f" ,
145+ } ,
146+ } ) ;
121147} ) ;
122148
123149test ( "@prop single, top level, nested" , ( ) => {
124150 const compiled = compile ( `
125151 .test {
126152 color: red;
127153 background-color: blue;
128- @prop background-color: ^ myBackgroundColor.test;
154+ @prop background-color: myBackgroundColor.test;
129155 }
130156 ` ) ;
131157
@@ -139,7 +165,7 @@ test("@prop single, top level, nested", () => {
139165 {
140166 color : "#f00" ,
141167 } ,
142- [ "#00f" , [ "^" , " myBackgroundColor", "test" ] ] ,
168+ [ "#00f" , [ "myBackgroundColor" , "test" ] ] ,
143169 ] ,
144170 s : [ 1 , 1 ] ,
145171 v : [ [ "__rn-css-color" , "#f00" ] ] ,
@@ -156,8 +182,8 @@ test("@prop multiple", () => {
156182 color: red;
157183 background-color: blue;
158184 @prop {
159- background-color: myBackgroundColor;
160- color: myColor;
185+ background-color: *. myBackgroundColor;
186+ color: *. myColor;
161187 }
162188 }
163189 ` ) ;
0 commit comments