1
1
import React from 'react' ;
2
- import { type AccessibilityRole , View } from 'react-native' ;
2
+ import { type AccessibilityRole , Switch , View } from 'react-native' ;
3
3
import render from '../../render' ;
4
4
import { screen } from '../../screen' ;
5
5
import '../extend-expect' ;
6
6
7
7
function renderViewsWithRole ( role : AccessibilityRole ) {
8
- return render (
8
+ render (
9
9
< >
10
10
< View
11
11
testID = { `${ role } -checked` }
@@ -30,6 +30,55 @@ function renderViewsWithRole(role: AccessibilityRole) {
30
30
) ;
31
31
}
32
32
33
+ test ( 'toBeCheck() with Switch' , ( ) => {
34
+ render (
35
+ < >
36
+ < Switch testID = "checked" value = { true } />
37
+ < Switch testID = "unchecked" value = { false } />
38
+ < Switch testID = "default" />
39
+ </ > ,
40
+ ) ;
41
+
42
+ const checked = screen . getByTestId ( 'checked' ) ;
43
+ const unchecked = screen . getByTestId ( 'unchecked' ) ;
44
+ const defaultView = screen . getByTestId ( 'default' ) ;
45
+
46
+ expect ( checked ) . toBeChecked ( ) ;
47
+ expect ( unchecked ) . not . toBeChecked ( ) ;
48
+ expect ( defaultView ) . not . toBeChecked ( ) ;
49
+
50
+ expect ( ( ) => expect ( checked ) . not . toBeChecked ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
51
+ "expect(element).not.toBeChecked()
52
+
53
+ Received element is checked:
54
+ <RCTSwitch
55
+ accessibilityRole="switch"
56
+ testID="checked"
57
+ value={true}
58
+ />"
59
+ ` ) ;
60
+ expect ( ( ) => expect ( unchecked ) . toBeChecked ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
61
+ "expect(element).toBeChecked()
62
+
63
+ Received element is not checked:
64
+ <RCTSwitch
65
+ accessibilityRole="switch"
66
+ testID="unchecked"
67
+ value={false}
68
+ />"
69
+ ` ) ;
70
+ expect ( ( ) => expect ( defaultView ) . toBeChecked ( ) ) . toThrowErrorMatchingInlineSnapshot ( `
71
+ "expect(element).toBeChecked()
72
+
73
+ Received element is not checked:
74
+ <RCTSwitch
75
+ accessibilityRole="switch"
76
+ testID="default"
77
+ value={false}
78
+ />"
79
+ ` ) ;
80
+ } ) ;
81
+
33
82
test ( 'toBeCheck() with checkbox role' , ( ) => {
34
83
renderViewsWithRole ( 'checkbox' ) ;
35
84
0 commit comments