1- import { Animated } from 'react-native' ;
1+ import { Animated , StyleSheet } from 'react-native' ;
22
3- import { describe , expect , it , jest } from '@jest/globals' ;
3+ import { describe , it , jest } from '@jest/globals' ;
44import { act } from '@testing-library/react-native' ;
55import color from 'color' ;
66
@@ -12,6 +12,15 @@ import { getChipColors } from '../Chip/helpers';
1212
1313const stateOpacity = tokens . md . sys . state . opacity ;
1414
15+ const getScaleValue = ( testID : string ) => {
16+ const style = StyleSheet . flatten ( screen . getByTestId ( testID ) . props . style ) ;
17+ const scale = style . transform ?. find (
18+ ( transform : { scale ?: Animated . Value | number } ) => 'scale' in transform
19+ ) ?. scale ;
20+
21+ return typeof scale === 'number' ? scale : scale ?. __getValue ( ) ;
22+ } ;
23+
1524it ( 'renders chip with onPress' , async ( ) => {
1625 const tree = (
1726 await render ( < Chip onPress = { ( ) => { } } > Example Chip</ Chip > )
@@ -70,10 +79,26 @@ it('renders selected chip', async () => {
7079 expect ( tree ) . toMatchSnapshot ( ) ;
7180} ) ;
7281
73- it ( 'renders disabled chip if there is no touch handler passed' , async ( ) => {
74- await render ( < Chip testID = "disabled -chip" > Disabled chip</ Chip > ) ;
82+ it ( 'does not mark chip disabled if there is no touch handler passed' , async ( ) => {
83+ await render ( < Chip testID = "informational -chip" > Informational chip</ Chip > ) ;
7584
76- expect ( screen . getByTestId ( 'disabled-chip' ) ) . toBeDisabled ( ) ;
85+ expect (
86+ screen . getByTestId ( 'informational-chip' ) . props . accessibilityState
87+ ) . toMatchObject ( {
88+ disabled : false ,
89+ } ) ;
90+ } ) ;
91+
92+ it ( 'marks chip disabled when disabled prop is passed' , async ( ) => {
93+ await render (
94+ < Chip disabled testID = "disabled-chip" >
95+ Disabled chip
96+ </ Chip >
97+ ) ;
98+
99+ expect ( screen . getByTestId ( 'disabled-chip' ) . props . accessibilityState ) . toMatchObject ( {
100+ disabled : true ,
101+ } ) ;
77102} ) ;
78103
79104it ( 'renders active chip if only onLongPress handler is passed' , async ( ) => {
@@ -83,7 +108,9 @@ it('renders active chip if only onLongPress handler is passed', async () => {
83108 </ Chip >
84109 ) ;
85110
86- expect ( screen . getByTestId ( 'active-chip' ) ) . toBeEnabled ( ) ;
111+ expect ( screen . getByTestId ( 'active-chip' ) . props . accessibilityState ) . toMatchObject ( {
112+ disabled : false ,
113+ } ) ;
87114} ) ;
88115
89116it ( 'renders chip with zero border radius' , async ( ) => {
@@ -93,9 +120,11 @@ it('renders chip with zero border radius', async () => {
93120 </ Chip >
94121 ) ;
95122
96- expect ( screen . getByTestId ( 'active-chip' ) ) . toHaveStyle ( {
97- borderRadius : 0 ,
98- } ) ;
123+ expect ( StyleSheet . flatten ( screen . getByTestId ( 'active-chip' ) . props . style ) ) . toMatchObject (
124+ {
125+ borderRadius : 0 ,
126+ }
127+ ) ;
99128} ) ;
100129
101130describe ( 'getChipColors - text color' , ( ) => {
@@ -385,9 +414,7 @@ it('animated value changes correctly', async () => {
385414 Example Chip
386415 </ Chip >
387416 ) ;
388- expect ( screen . getByTestId ( 'chip-container-outer-layer' ) ) . toHaveStyle ( {
389- transform : [ { scale : 1 } ] ,
390- } ) ;
417+ expect ( getScaleValue ( 'chip-container-outer-layer' ) ) . toBe ( 1 ) ;
391418
392419 Animated . timing ( value , {
393420 toValue : 1.5 ,
@@ -398,7 +425,5 @@ it('animated value changes correctly', async () => {
398425 await act ( ( ) => {
399426 jest . advanceTimersByTime ( 200 ) ;
400427 } ) ;
401- expect ( screen . getByTestId ( 'chip-container-outer-layer' ) ) . toHaveStyle ( {
402- transform : [ { scale : 1.5 } ] ,
403- } ) ;
428+ expect ( getScaleValue ( 'chip-container-outer-layer' ) ) . toBe ( 1.5 ) ;
404429} ) ;
0 commit comments