@@ -17,7 +17,7 @@ test('toContainElement() supports basic case', () => {
1717
1818 expect ( ( ) => expect ( parent ) . not . toContainElement ( child ) )
1919 . toThrowErrorMatchingInlineSnapshot ( `
20- "expect(element ).not.toContainElement(element)
20+ "expect(container ).not.toContainElement(element)
2121
2222 <View
2323 testID="parent"
@@ -44,10 +44,11 @@ test('toContainElement() supports negative case', () => {
4444 const view2 = screen . getByTestId ( 'view2' ) ;
4545
4646 expect ( view1 ) . not . toContainElement ( view2 ) ;
47+ expect ( view2 ) . not . toContainElement ( view1 ) ;
4748
4849 expect ( ( ) => expect ( view1 ) . toContainElement ( view2 ) )
4950 . toThrowErrorMatchingInlineSnapshot ( `
50- "expect(element ).toContainElement(element)
51+ "expect(container ).toContainElement(element)
5152
5253 <View
5354 testID="view1"
@@ -62,7 +63,21 @@ test('toContainElement() supports negative case', () => {
6263 ` ) ;
6364} ) ;
6465
65- test ( 'toContainElement() passing null' , ( ) => {
66+ test ( 'toContainElement() handles null container' , ( ) => {
67+ render ( < View testID = "view" /> ) ;
68+
69+ const view = screen . getByTestId ( 'view' ) ;
70+
71+ expect ( ( ) => expect ( null ) . toContainElement ( view ) )
72+ . toThrowErrorMatchingInlineSnapshot ( `
73+ "expect(received).toContainElement()
74+
75+ received value must be a host element.
76+ Received has value: null"
77+ ` ) ;
78+ } ) ;
79+
80+ test ( 'toContainElement() handles null element' , ( ) => {
6681 render ( < View testID = "view" /> ) ;
6782
6883 const view = screen . getByTestId ( 'view' ) ;
@@ -71,7 +86,7 @@ test('toContainElement() passing null', () => {
7186
7287 expect ( ( ) => expect ( view ) . toContainElement ( null ) )
7388 . toThrowErrorMatchingInlineSnapshot ( `
74- "expect(element ).toContainElement(element)
89+ "expect(container ).toContainElement(element)
7590
7691 <View
7792 testID="view"
@@ -84,32 +99,18 @@ test('toContainElement() passing null', () => {
8499 ` ) ;
85100} ) ;
86101
87- test ( 'toContainElement() on null elements' , ( ) => {
88- render ( < View testID = "view" /> ) ;
89-
90- const view = screen . getByTestId ( 'view' ) ;
91-
92- expect ( ( ) => expect ( null ) . toContainElement ( view ) )
93- . toThrowErrorMatchingInlineSnapshot ( `
94- "expect(received).toContainElement()
95-
96- received value must be a host element.
97- Received has value: null"
98- ` ) ;
99- } ) ;
100-
101- test ( 'toContainElement() on non-React elements' , ( ) => {
102+ test ( 'toContainElement() handles non-element container' , ( ) => {
102103 render ( < View testID = "view" /> ) ;
103104
104105 const view = screen . getByTestId ( 'view' ) ;
105106
106- expect ( ( ) => expect ( { name : 'Non-React element' } ) . not . toContainElement ( view ) )
107+ expect ( ( ) => expect ( { name : 'non- element' } ) . not . toContainElement ( view ) )
107108 . toThrowErrorMatchingInlineSnapshot ( `
108109 "expect(received).not.toContainElement()
109110
110111 received value must be a host element.
111112 Received has type: object
112- Received has value: {"name": "Non-React element"}"
113+ Received has value: {"name": "non- element"}"
113114 ` ) ;
114115
115116 expect ( ( ) => expect ( true ) . not . toContainElement ( view ) )
@@ -122,30 +123,19 @@ test('toContainElement() on non-React elements', () => {
122123 ` ) ;
123124} ) ;
124125
125- test ( 'toContainElement() passing non-React element' , ( ) => {
126+ test ( 'toContainElement() handles non-element element' , ( ) => {
126127 render ( < View testID = "view" /> ) ;
127128
128129 const view = screen . getByTestId ( 'view' ) ;
129130
130131 expect ( ( ) =>
131132 // @ts -expect-error
132- expect ( view ) . not . toContainElement ( true )
133+ expect ( view ) . not . toContainElement ( { name : 'non-element' } )
133134 ) . toThrowErrorMatchingInlineSnapshot ( `
134135 "expect(received).not.toContainElement()
135136
136137 received value must be a host element.
137- Received has type: boolean
138- Received has value: true"
139- ` ) ;
140- } ) ;
141-
142- test ( 'toContainElement() passing null on non-React element' , ( ) => {
143- expect ( ( ) => expect ( true ) . not . toContainElement ( null ) )
144- . toThrowErrorMatchingInlineSnapshot ( `
145- "expect(received).not.toContainElement()
146-
147- received value must be a host element.
148- Received has type: boolean
149- Received has value: true"
138+ Received has type: object
139+ Received has value: {"name": "non-element"}"
150140 ` ) ;
151141} ) ;
0 commit comments