11import React from 'react' ;
2- import { Pressable , StyleSheet , View } from 'react-native' ;
2+ import { Pressable , StyleSheet , Text , View } from 'react-native' ;
33
44import { render , screen } from '../..' ;
55
@@ -70,8 +70,8 @@ test('toHaveStyle error messages', () => {
7070 - Expected
7171 + Received
7272
73- - backgroundColor: red;
74- + backgroundColor: blue;"
73+ - backgroundColor: " red" ;
74+ + backgroundColor: " blue" ;"
7575 ` ) ;
7676
7777 expect ( ( ) =>
@@ -85,7 +85,7 @@ test('toHaveStyle error messages', () => {
8585 - Expected
8686 + Received
8787
88- backgroundColor: blue;
88+ backgroundColor: " blue" ;
8989 transform: [
9090 {
9191 - "scale": 1
@@ -102,9 +102,9 @@ test('toHaveStyle error messages', () => {
102102 "expect(element).not.toHaveStyle()
103103
104104 Expected element not to have style:
105- backgroundColor: blue;
105+ backgroundColor: " blue" ;
106106 Received:
107- backgroundColor: blue;"
107+ backgroundColor: " blue" ;"
108108 ` ) ;
109109
110110 expect ( ( ) => expect ( view ) . toHaveStyle ( { fontWeight : 'bold' } ) )
@@ -114,17 +114,17 @@ test('toHaveStyle error messages', () => {
114114 - Expected
115115 + Received
116116
117- - fontWeight: bold;"
117+ - fontWeight: " bold" ;"
118118 ` ) ;
119119
120120 expect ( ( ) => expect ( view ) . not . toHaveStyle ( { backgroundColor : 'blue' } ) )
121121 . toThrowErrorMatchingInlineSnapshot ( `
122122 "expect(element).not.toHaveStyle()
123123
124124 Expected element not to have style:
125- backgroundColor: blue;
125+ backgroundColor: " blue" ;
126126 Received:
127- backgroundColor: blue;"
127+ backgroundColor: " blue" ;"
128128 ` ) ;
129129} ) ;
130130
@@ -168,3 +168,26 @@ test('toHaveStyle() supports Pressable with function "style" prop', () => {
168168
169169 expect ( screen . getByTestId ( 'view' ) ) . toHaveStyle ( { backgroundColor : 'blue' } ) ;
170170} ) ;
171+
172+ test ( 'toHaveStyle() to differentiate number vs string values' , ( ) => {
173+ const screen = render (
174+ < Text
175+ testID = "view"
176+ style = { {
177+ fontWeight : '600' ,
178+ } }
179+ /> ,
180+ ) ;
181+
182+ const view = screen . getByTestId ( 'view' ) ;
183+ expect ( view ) . toHaveStyle ( { fontWeight : '600' } ) ;
184+ expect ( ( ) => expect ( view ) . toHaveStyle ( { fontWeight : 600 } ) ) . toThrowErrorMatchingInlineSnapshot ( `
185+ "expect(element).toHaveStyle()
186+
187+ - Expected
188+ + Received
189+
190+ - fontWeight: 600;
191+ + fontWeight: "600";"
192+ ` ) ;
193+ } ) ;
0 commit comments