@@ -51,16 +51,19 @@ class Banana extends React.Component {
51
51
}
52
52
}
53
53
54
- test ( 'getByTestId' , ( ) => {
55
- const { getByTestId } = render ( < Banana /> ) ;
54
+ test ( 'getByTestId, queryByTestId ' , ( ) => {
55
+ const { getByTestId, queryByTestId } = render ( < Banana /> ) ;
56
56
const component = getByTestId ( 'bananaFresh' ) ;
57
57
58
58
expect ( component . props . children ) . toBe ( 'not fresh' ) ;
59
59
expect ( ( ) => getByTestId ( 'InExistent' ) ) . toThrow ( ) ;
60
+
61
+ expect ( getByTestId ( 'bananaFresh' ) ) . toBe ( component ) ;
62
+ expect ( queryByTestId ( 'InExistent' ) ) . toBeNull ( ) ;
60
63
} ) ;
61
64
62
- test ( 'getByName' , ( ) => {
63
- const { getByTestId, getByName } = render ( < Banana /> ) ;
65
+ test ( 'getByName, queryByName ' , ( ) => {
66
+ const { getByTestId, getByName, queryByName } = render ( < Banana /> ) ;
64
67
const bananaFresh = getByTestId ( 'bananaFresh' ) ;
65
68
const button = getByName ( 'Button' ) ;
66
69
@@ -72,22 +75,27 @@ test('getByName', () => {
72
75
sameButton . props . onPress ( ) ;
73
76
74
77
expect ( bananaFresh . props . children ) . toBe ( 'not fresh' ) ;
75
-
76
78
expect ( ( ) => getByName ( 'InExistent' ) ) . toThrow ( ) ;
79
+
80
+ expect ( queryByName ( 'Button' ) ) . toBe ( button ) ;
81
+ expect ( queryByName ( 'InExistent' ) ) . toBeNull ( ) ;
77
82
} ) ;
78
83
79
- test ( 'getAllByName' , ( ) => {
80
- const { getAllByName } = render ( < Banana /> ) ;
84
+ test ( 'getAllByName, queryAllByName ' , ( ) => {
85
+ const { getAllByName, queryAllByName } = render ( < Banana /> ) ;
81
86
const [ text , status , button ] = getAllByName ( 'Text' ) ;
82
87
83
88
expect ( text . props . children ) . toBe ( 'Is the banana fresh?' ) ;
84
89
expect ( status . props . children ) . toBe ( 'not fresh' ) ;
85
90
expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
86
91
expect ( ( ) => getAllByName ( 'InExistent' ) ) . toThrow ( ) ;
92
+
93
+ expect ( queryAllByName ( 'Text' ) [ 1 ] ) . toBe ( status ) ;
94
+ expect ( queryAllByName ( 'InExistent' ) ) . toHaveLength ( 0 ) ;
87
95
} ) ;
88
96
89
- test ( 'getByText' , ( ) => {
90
- const { getByText } = render ( < Banana /> ) ;
97
+ test ( 'getByText, queryByText ' , ( ) => {
98
+ const { getByText, queryByText } = render ( < Banana /> ) ;
91
99
const button = getByText ( / c h a n g e / i) ;
92
100
93
101
expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
@@ -96,30 +104,42 @@ test('getByText', () => {
96
104
97
105
expect ( sameButton . props . children ) . toBe ( 'not fresh' ) ;
98
106
expect ( ( ) => getByText ( 'InExistent' ) ) . toThrow ( ) ;
107
+
108
+ expect ( queryByText ( / c h a n g e / i) ) . toBe ( button ) ;
109
+ expect ( queryByText ( 'InExistent' ) ) . toBeNull ( ) ;
99
110
} ) ;
100
111
101
- test ( 'getAllByText' , ( ) => {
102
- const { getAllByText } = render ( < Banana /> ) ;
103
- const button = getAllByText ( / f r e s h / i) ;
112
+ test ( 'getAllByText, queryAllByText ' , ( ) => {
113
+ const { getAllByText, queryAllByText } = render ( < Banana /> ) ;
114
+ const buttons = getAllByText ( / f r e s h / i) ;
104
115
105
- expect ( button ) . toHaveLength ( 3 ) ;
116
+ expect ( buttons ) . toHaveLength ( 3 ) ;
106
117
expect ( ( ) => getAllByText ( 'InExistent' ) ) . toThrow ( ) ;
118
+
119
+ expect ( queryAllByText ( / f r e s h / i) ) . toEqual ( buttons ) ;
120
+ expect ( queryAllByText ( 'InExistent' ) ) . toHaveLength ( 0 ) ;
107
121
} ) ;
108
122
109
- test ( 'getByProps' , ( ) => {
110
- const { getByProps } = render ( < Banana /> ) ;
123
+ test ( 'getByProps, queryByProps ' , ( ) => {
124
+ const { getByProps, queryByProps } = render ( < Banana /> ) ;
111
125
const primaryType = getByProps ( { type : 'primary' } ) ;
112
126
113
127
expect ( primaryType . props . children ) . toBe ( 'Change freshness!' ) ;
114
128
expect ( ( ) => getByProps ( { type : 'inexistent' } ) ) . toThrow ( ) ;
129
+
130
+ expect ( queryByProps ( { type : 'primary' } ) ) . toBe ( primaryType ) ;
131
+ expect ( queryByProps ( { type : 'inexistent' } ) ) . toBeNull ( ) ;
115
132
} ) ;
116
133
117
- test ( 'getAllByProps ' , ( ) => {
118
- const { getAllByProps } = render ( < Banana /> ) ;
134
+ test ( 'getAllByProp, queryAllByProps ' , ( ) => {
135
+ const { getAllByProps, queryAllByProps } = render ( < Banana /> ) ;
119
136
const primaryTypes = getAllByProps ( { type : 'primary' } ) ;
120
137
121
138
expect ( primaryTypes ) . toHaveLength ( 1 ) ;
122
139
expect ( ( ) => getAllByProps ( { type : 'inexistent' } ) ) . toThrow ( ) ;
140
+
141
+ expect ( queryAllByProps ( { type : 'primary' } ) ) . toEqual ( primaryTypes ) ;
142
+ expect ( queryAllByProps ( { type : 'inexistent' } ) ) . toHaveLength ( 0 ) ;
123
143
} ) ;
124
144
125
145
test ( 'update' , ( ) => {
0 commit comments