@@ -17,7 +17,7 @@ test('toContainElement() supports basic case', () => {
17
17
18
18
expect ( ( ) => expect ( parent ) . not . toContainElement ( child ) )
19
19
. toThrowErrorMatchingInlineSnapshot ( `
20
- "expect(element ).not.toContainElement(element)
20
+ "expect(container ).not.toContainElement(element)
21
21
22
22
<View
23
23
testID="parent"
@@ -44,10 +44,11 @@ test('toContainElement() supports negative case', () => {
44
44
const view2 = screen . getByTestId ( 'view2' ) ;
45
45
46
46
expect ( view1 ) . not . toContainElement ( view2 ) ;
47
+ expect ( view2 ) . not . toContainElement ( view1 ) ;
47
48
48
49
expect ( ( ) => expect ( view1 ) . toContainElement ( view2 ) )
49
50
. toThrowErrorMatchingInlineSnapshot ( `
50
- "expect(element ).toContainElement(element)
51
+ "expect(container ).toContainElement(element)
51
52
52
53
<View
53
54
testID="view1"
@@ -62,7 +63,21 @@ test('toContainElement() supports negative case', () => {
62
63
` ) ;
63
64
} ) ;
64
65
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' , ( ) => {
66
81
render ( < View testID = "view" /> ) ;
67
82
68
83
const view = screen . getByTestId ( 'view' ) ;
@@ -71,7 +86,7 @@ test('toContainElement() passing null', () => {
71
86
72
87
expect ( ( ) => expect ( view ) . toContainElement ( null ) )
73
88
. toThrowErrorMatchingInlineSnapshot ( `
74
- "expect(element ).toContainElement(element)
89
+ "expect(container ).toContainElement(element)
75
90
76
91
<View
77
92
testID="view"
@@ -84,32 +99,18 @@ test('toContainElement() passing null', () => {
84
99
` ) ;
85
100
} ) ;
86
101
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' , ( ) => {
102
103
render ( < View testID = "view" /> ) ;
103
104
104
105
const view = screen . getByTestId ( 'view' ) ;
105
106
106
- expect ( ( ) => expect ( { name : 'Non-React element' } ) . not . toContainElement ( view ) )
107
+ expect ( ( ) => expect ( { name : 'non- element' } ) . not . toContainElement ( view ) )
107
108
. toThrowErrorMatchingInlineSnapshot ( `
108
109
"expect(received).not.toContainElement()
109
110
110
111
received value must be a host element.
111
112
Received has type: object
112
- Received has value: {"name": "Non-React element"}"
113
+ Received has value: {"name": "non- element"}"
113
114
` ) ;
114
115
115
116
expect ( ( ) => expect ( true ) . not . toContainElement ( view ) )
@@ -122,30 +123,19 @@ test('toContainElement() on non-React elements', () => {
122
123
` ) ;
123
124
} ) ;
124
125
125
- test ( 'toContainElement() passing non-React element' , ( ) => {
126
+ test ( 'toContainElement() handles non-element element' , ( ) => {
126
127
render ( < View testID = "view" /> ) ;
127
128
128
129
const view = screen . getByTestId ( 'view' ) ;
129
130
130
131
expect ( ( ) =>
131
132
// @ts -expect-error
132
- expect ( view ) . not . toContainElement ( true )
133
+ expect ( view ) . not . toContainElement ( { name : 'non-element' } )
133
134
) . toThrowErrorMatchingInlineSnapshot ( `
134
135
"expect(received).not.toContainElement()
135
136
136
137
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"}"
150
140
` ) ;
151
141
} ) ;
0 commit comments