@@ -51,16 +51,19 @@ class Banana extends React.Component {
5151 }
5252}
5353
54- test ( 'getByTestId' , ( ) => {
55- const { getByTestId } = render ( < Banana /> ) ;
54+ test ( 'getByTestId, queryByTestId ' , ( ) => {
55+ const { getByTestId, queryByTestId } = render ( < Banana /> ) ;
5656 const component = getByTestId ( 'bananaFresh' ) ;
5757
5858 expect ( component . props . children ) . toBe ( 'not fresh' ) ;
5959 expect ( ( ) => getByTestId ( 'InExistent' ) ) . toThrow ( ) ;
60+
61+ expect ( getByTestId ( 'bananaFresh' ) ) . toBe ( component ) ;
62+ expect ( queryByTestId ( 'InExistent' ) ) . toBeNull ( ) ;
6063} ) ;
6164
62- test ( 'getByName' , ( ) => {
63- const { getByTestId, getByName } = render ( < Banana /> ) ;
65+ test ( 'getByName, queryByName ' , ( ) => {
66+ const { getByTestId, getByName, queryByName } = render ( < Banana /> ) ;
6467 const bananaFresh = getByTestId ( 'bananaFresh' ) ;
6568 const button = getByName ( 'Button' ) ;
6669
@@ -72,22 +75,27 @@ test('getByName', () => {
7275 sameButton . props . onPress ( ) ;
7376
7477 expect ( bananaFresh . props . children ) . toBe ( 'not fresh' ) ;
75-
7678 expect ( ( ) => getByName ( 'InExistent' ) ) . toThrow ( ) ;
79+
80+ expect ( queryByName ( 'Button' ) ) . toBe ( button ) ;
81+ expect ( queryByName ( 'InExistent' ) ) . toBeNull ( ) ;
7782} ) ;
7883
79- test ( 'getAllByName' , ( ) => {
80- const { getAllByName } = render ( < Banana /> ) ;
84+ test ( 'getAllByName, queryAllByName ' , ( ) => {
85+ const { getAllByName, queryAllByName } = render ( < Banana /> ) ;
8186 const [ text , status , button ] = getAllByName ( 'Text' ) ;
8287
8388 expect ( text . props . children ) . toBe ( 'Is the banana fresh?' ) ;
8489 expect ( status . props . children ) . toBe ( 'not fresh' ) ;
8590 expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
8691 expect ( ( ) => getAllByName ( 'InExistent' ) ) . toThrow ( ) ;
92+
93+ expect ( queryAllByName ( 'Text' ) [ 1 ] ) . toBe ( status ) ;
94+ expect ( queryAllByName ( 'InExistent' ) ) . toHaveLength ( 0 ) ;
8795} ) ;
8896
89- test ( 'getByText' , ( ) => {
90- const { getByText } = render ( < Banana /> ) ;
97+ test ( 'getByText, queryByText ' , ( ) => {
98+ const { getByText, queryByText } = render ( < Banana /> ) ;
9199 const button = getByText ( / c h a n g e / i) ;
92100
93101 expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
@@ -96,30 +104,42 @@ test('getByText', () => {
96104
97105 expect ( sameButton . props . children ) . toBe ( 'not fresh' ) ;
98106 expect ( ( ) => getByText ( 'InExistent' ) ) . toThrow ( ) ;
107+
108+ expect ( queryByText ( / c h a n g e / i) ) . toBe ( button ) ;
109+ expect ( queryByText ( 'InExistent' ) ) . toBeNull ( ) ;
99110} ) ;
100111
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) ;
104115
105- expect ( button ) . toHaveLength ( 3 ) ;
116+ expect ( buttons ) . toHaveLength ( 3 ) ;
106117 expect ( ( ) => getAllByText ( 'InExistent' ) ) . toThrow ( ) ;
118+
119+ expect ( queryAllByText ( / f r e s h / i) ) . toEqual ( buttons ) ;
120+ expect ( queryAllByText ( 'InExistent' ) ) . toHaveLength ( 0 ) ;
107121} ) ;
108122
109- test ( 'getByProps' , ( ) => {
110- const { getByProps } = render ( < Banana /> ) ;
123+ test ( 'getByProps, queryByProps ' , ( ) => {
124+ const { getByProps, queryByProps } = render ( < Banana /> ) ;
111125 const primaryType = getByProps ( { type : 'primary' } ) ;
112126
113127 expect ( primaryType . props . children ) . toBe ( 'Change freshness!' ) ;
114128 expect ( ( ) => getByProps ( { type : 'inexistent' } ) ) . toThrow ( ) ;
129+
130+ expect ( queryByProps ( { type : 'primary' } ) ) . toBe ( primaryType ) ;
131+ expect ( queryByProps ( { type : 'inexistent' } ) ) . toBeNull ( ) ;
115132} ) ;
116133
117- test ( 'getAllByProps ' , ( ) => {
118- const { getAllByProps } = render ( < Banana /> ) ;
134+ test ( 'getAllByProp, queryAllByProps ' , ( ) => {
135+ const { getAllByProps, queryAllByProps } = render ( < Banana /> ) ;
119136 const primaryTypes = getAllByProps ( { type : 'primary' } ) ;
120137
121138 expect ( primaryTypes ) . toHaveLength ( 1 ) ;
122139 expect ( ( ) => getAllByProps ( { type : 'inexistent' } ) ) . toThrow ( ) ;
140+
141+ expect ( queryAllByProps ( { type : 'primary' } ) ) . toEqual ( primaryTypes ) ;
142+ expect ( queryAllByProps ( { type : 'inexistent' } ) ) . toHaveLength ( 0 ) ;
123143} ) ;
124144
125145test ( 'update' , ( ) => {
0 commit comments