@@ -157,4 +157,42 @@ describe('unexpected-dom', function () {
157
157
} ) ;
158
158
} ) ;
159
159
160
+ describe ( 'to have children' , function ( ) {
161
+ describe ( 'with no children flag' , function ( ) {
162
+ it ( 'should match element with no children' , function ( ) {
163
+ this . body . innerHTML = '<div></div>' ;
164
+ var el = this . body . firstChild ;
165
+
166
+ expect ( el , 'to have no children' ) ;
167
+ } ) ;
168
+
169
+ it ( 'should fail on element with HTMLElement children' , function ( ) {
170
+ this . body . innerHTML = '<div><p></p></div>' ;
171
+ var el = this . body . firstChild ;
172
+
173
+ expect ( function ( ) {
174
+ expect ( el , 'to have no children' ) ;
175
+ } , 'to throw' , / ^ e x p e c t e d < d i v > ...< \/ d i v > t o h a v e n o c h i l d r e n / ) ;
176
+ } ) ;
177
+
178
+ it ( 'should fail on element with HTMLComment children' , function ( ) {
179
+ this . body . innerHTML = '<div><!-- Comment --></div>' ;
180
+ var el = this . body . firstChild ;
181
+
182
+ expect ( function ( ) {
183
+ expect ( el , 'to have no children' ) ;
184
+ } , 'to throw' , / ^ e x p e c t e d < d i v \/ > t o h a v e n o c h i l d r e n / ) ;
185
+ } ) ;
186
+
187
+ it ( 'should fail on element with TextNode children' , function ( ) {
188
+ this . body . innerHTML = '<div>I am a text</div>' ;
189
+ var el = this . body . firstChild ;
190
+
191
+ expect ( function ( ) {
192
+ expect ( el , 'to have no children' ) ;
193
+ } , 'to throw' , / ^ e x p e c t e d < d i v \/ > t o h a v e n o c h i l d r e n / ) ;
194
+ } ) ;
195
+ } ) ;
196
+ } ) ;
197
+
160
198
} ) ;
0 commit comments