@@ -2,6 +2,7 @@ import React from 'react';
22import {
33 Button ,
44 Pressable ,
5+ Switch ,
56 Text ,
67 TextInput ,
78 TouchableHighlight ,
@@ -18,7 +19,7 @@ test('toBeDisabled()/toBeEnabled() supports basic case', async () => {
1819 < View >
1920 < View testID = "disabled-parent" aria-disabled >
2021 < View >
21- < View testID = "disabled- child" />
22+ < View testID = "child-of-disabled " />
2223 </ View >
2324 </ View >
2425 < View >
@@ -31,7 +32,7 @@ test('toBeDisabled()/toBeEnabled() supports basic case', async () => {
3132 ) ;
3233
3334 expect ( screen . getByTestId ( 'disabled-parent' ) ) . toBeDisabled ( ) ;
34- expect ( screen . getByTestId ( 'disabled- child' ) ) . toBeDisabled ( ) ;
35+ expect ( screen . getByTestId ( 'child-of-disabled ' ) ) . not . toBeDisabled ( ) ;
3536 expect ( screen . getByTestId ( 'enabled-view' ) ) . not . toBeDisabled ( ) ;
3637 expect ( screen . getByTestId ( 'enabled-text' ) ) . not . toBeDisabled ( ) ;
3738 expect ( screen . getByTestId ( 'enabled-text-input' ) ) . not . toBeDisabled ( ) ;
@@ -59,7 +60,7 @@ test('toBeDisabled()/toBeEnabled() supports basic case', async () => {
5960 ` ) ;
6061
6162 expect ( screen . getByTestId ( 'disabled-parent' ) ) . not . toBeEnabled ( ) ;
62- expect ( screen . getByTestId ( 'disabled- child' ) ) . not . toBeEnabled ( ) ;
63+ expect ( screen . getByTestId ( 'child-of-disabled ' ) ) . toBeEnabled ( ) ;
6364 expect ( screen . getByTestId ( 'enabled-view' ) ) . toBeEnabled ( ) ;
6465 expect ( screen . getByTestId ( 'enabled-text' ) ) . toBeEnabled ( ) ;
6566 expect ( screen . getByTestId ( 'enabled-text-input' ) ) . toBeEnabled ( ) ;
@@ -99,8 +100,8 @@ test('toBeDisabled()/toBeEnabled() supports Pressable with "disabled" prop', asy
99100 expect ( pressable ) . not . toBeEnabled ( ) ;
100101
101102 const title = screen . getByText ( 'Button' ) ;
102- expect ( title ) . toBeDisabled ( ) ;
103- expect ( title ) . not . toBeEnabled ( ) ;
103+ expect ( title ) . not . toBeDisabled ( ) ;
104+ expect ( title ) . toBeEnabled ( ) ;
104105
105106 expect ( ( ) => expect ( pressable ) . toBeEnabled ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
106107 "expect(instance).toBeEnabled()
@@ -132,19 +133,19 @@ test('toBeDisabled()/toBeEnabled() supports Pressable with "disabled" prop', asy
132133 />"
133134 ` ) ;
134135
135- expect ( ( ) => expect ( title ) . toBeEnabled ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
136- "expect(instance).toBeEnabled ()
136+ expect ( ( ) => expect ( title ) . toBeDisabled ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
137+ "expect(instance).toBeDisabled ()
137138
138- Received instance is not enabled :
139+ Received instance is not disabled :
139140 <Text>
140141 Button
141142 </Text>"
142143 ` ) ;
143144
144- expect ( ( ) => expect ( title ) . not . toBeDisabled ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
145- "expect(instance).not.toBeDisabled ()
145+ expect ( ( ) => expect ( title ) . not . toBeEnabled ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
146+ "expect(instance).not.toBeEnabled ()
146147
147- Received instance is disabled :
148+ Received instance is enabled :
148149 <Text>
149150 Button
150151 </Text>"
@@ -164,7 +165,10 @@ test.each([
164165 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
165166 // @ts -ignore - JSX element type 'Component' does not have any construct or call signatures.
166167 < Component disabled testID = "subject" >
167- < Text > Button</ Text >
168+ { /* `TouchableWithoutFeedback` and `TouchableNativeFeedback` render their child as the host. */ }
169+ < View >
170+ < Text > Button</ Text >
171+ </ View >
168172 </ Component > ,
169173 ) ;
170174
@@ -173,13 +177,13 @@ test.each([
173177 expect ( touchable ) . not . toBeEnabled ( ) ;
174178
175179 const title = screen . getByText ( 'Button' ) ;
176- expect ( title ) . toBeDisabled ( ) ;
177- expect ( title ) . not . toBeEnabled ( ) ;
180+ expect ( title ) . not . toBeDisabled ( ) ;
181+ expect ( title ) . toBeEnabled ( ) ;
178182
179183 expect ( ( ) => expect ( touchable ) . toBeEnabled ( ) ) . toThrow ( ) ;
180184 expect ( ( ) => expect ( touchable ) . not . toBeDisabled ( ) ) . toThrow ( ) ;
181- expect ( ( ) => expect ( title ) . toBeEnabled ( ) ) . toThrow ( ) ;
182- expect ( ( ) => expect ( title ) . not . toBeDisabled ( ) ) . toThrow ( ) ;
185+ expect ( ( ) => expect ( title ) . toBeDisabled ( ) ) . toThrow ( ) ;
186+ expect ( ( ) => expect ( title ) . not . toBeEnabled ( ) ) . toThrow ( ) ;
183187 } ,
184188) ;
185189
@@ -256,6 +260,48 @@ test('toBeDisabled()/toBeEnabled() supports "editable" prop on TextInput', async
256260 expect ( screen . getByTestId ( 'disabled' ) ) . not . toBeEnabled ( ) ;
257261} ) ;
258262
263+ test ( 'toBeDisabled()/toBeEnabled() supports "readOnly" prop on TextInput' , async ( ) => {
264+ await render (
265+ < View >
266+ < TextInput testID = "read-only" readOnly />
267+ < TextInput testID = "read-only-false" readOnly = { false } />
268+ </ View > ,
269+ ) ;
270+
271+ expect ( screen . getByTestId ( 'read-only' ) ) . toBeDisabled ( ) ;
272+ expect ( screen . getByTestId ( 'read-only-false' ) ) . toBeEnabled ( ) ;
273+ } ) ;
274+
275+ test ( 'toBeDisabled()/toBeEnabled() supports "disabled" prop on Switch' , async ( ) => {
276+ await render (
277+ < View >
278+ < Switch testID = "enabled" />
279+ < Switch testID = "disabled" disabled />
280+ </ View > ,
281+ ) ;
282+
283+ expect ( screen . getByTestId ( 'enabled' ) ) . toBeEnabled ( ) ;
284+ expect ( screen . getByTestId ( 'disabled' ) ) . toBeDisabled ( ) ;
285+ } ) ;
286+
287+ test ( 'toBeDisabled()/toBeEnabled() does not inherit disabled state from ancestors' , async ( ) => {
288+ await render (
289+ < View >
290+ < View aria-disabled >
291+ < Pressable testID = "in-disabled-view" />
292+ </ View >
293+ < Pressable disabled >
294+ < Pressable testID = "in-disabled-pressable" />
295+ </ Pressable >
296+ </ View > ,
297+ ) ;
298+
299+ expect ( screen . getByTestId ( 'in-disabled-view' ) ) . toBeEnabled ( ) ;
300+ expect ( screen . getByTestId ( 'in-disabled-view' ) ) . not . toBeDisabled ( ) ;
301+ expect ( screen . getByTestId ( 'in-disabled-pressable' ) ) . toBeEnabled ( ) ;
302+ expect ( screen . getByTestId ( 'in-disabled-pressable' ) ) . not . toBeDisabled ( ) ;
303+ } ) ;
304+
259305test ( 'toBeDisabled()/toBeEnabled() supports "disabled" prop on Button' , async ( ) => {
260306 await render (
261307 < View >
0 commit comments