@@ -288,32 +288,46 @@ describe("[Unit] ElementAssertion.test.ts", () => {
288
288
const parentElementAssertion = new ElementAssertion ( parent ) ;
289
289
const child = element . getByTestId ( "childId" ) ;
290
290
const text = element . getByTestId ( "textId" ) ;
291
+ const textElementAssertion = new ElementAssertion ( text ) ;
291
292
292
- context ( "when the container element contains the target element" , ( ) => {
293
- it ( "returns the assertion instance" , ( ) => {
294
- expect ( containerElementAssertion . toContainElement ( parent ) ) . toBe ( containerElementAssertion ) ;
295
- expect ( containerElementAssertion . toContainElement ( child ) ) . toBe ( containerElementAssertion ) ;
296
- expect ( containerElementAssertion . toContainElement ( text ) ) . toBe ( containerElementAssertion ) ;
297
- expect ( parentElementAssertion . toContainElement ( child ) ) . toBe ( parentElementAssertion ) ;
293
+ context ( "when the element has children" , ( ) => {
294
+ context ( "and the target element is found in the children's element" , ( ) => {
295
+ it ( "returns the assertion instance" , ( ) => {
296
+ expect ( containerElementAssertion . toContainElement ( parent ) ) . toBe ( containerElementAssertion ) ;
297
+ expect ( containerElementAssertion . toContainElement ( child ) ) . toBe ( containerElementAssertion ) ;
298
+ expect ( containerElementAssertion . toContainElement ( text ) ) . toBe ( containerElementAssertion ) ;
299
+ expect ( parentElementAssertion . toContainElement ( child ) ) . toBe ( parentElementAssertion ) ;
300
+ } ) ;
301
+
302
+ it ( "throws an error for negative assertion" , ( ) => {
303
+ expect ( ( ) => containerElementAssertion . not . toContainElement ( parent ) )
304
+ . toThrowError ( AssertionError )
305
+ . toHaveMessage ( "Expected element <View ... /> NOT to contain element <View ... />." ) ;
306
+ expect ( ( ) => containerElementAssertion . not . toContainElement ( text ) )
307
+ . toThrowError ( AssertionError )
308
+ . toHaveMessage ( "Expected element <View ... /> NOT to contain element <Text ... />." ) ;
309
+ } ) ;
298
310
} ) ;
299
311
300
- it ( "returns the assertion instance for negated assertions when the target element is not contained" , ( ) => {
301
- expect ( parentElementAssertion . not . toContainElement ( text ) ) . toBeEqual ( parentElementAssertion ) ;
302
- expect ( parentElementAssertion . not . toContainElement ( container ) ) . toBeEqual ( parentElementAssertion ) ;
312
+ context ( "and the target element is NOT found in the children's element" , ( ) => {
313
+ it ( "throws an error" , ( ) => {
314
+ expect ( ( ) => parentElementAssertion . toContainElement ( text ) )
315
+ . toThrowError ( AssertionError )
316
+ . toHaveMessage ( "Expected element <View ... /> to contain element <Text ... />." ) ;
317
+ } ) ;
318
+
319
+ it ( "returns the assertion instance for negative assertion" , ( ) => {
320
+ expect ( parentElementAssertion . not . toContainElement ( text ) ) . toBeEqual ( parentElementAssertion ) ;
321
+ expect ( parentElementAssertion . not . toContainElement ( container ) ) . toBeEqual ( parentElementAssertion ) ;
322
+ } ) ;
303
323
} ) ;
304
324
} ) ;
305
325
306
- context ( "when the container element does NOT contain the target element " , ( ) => {
326
+ context ( "when the element does NOT have children " , ( ) => {
307
327
it ( "throws an error" , ( ) => {
308
- expect ( ( ) => containerElementAssertion . not . toContainElement ( parent ) )
309
- . toThrowError ( AssertionError )
310
- . toHaveMessage ( "Expected element <View ... /> NOT to contain element <View ... />." ) ;
311
- expect ( ( ) => containerElementAssertion . not . toContainElement ( text ) )
312
- . toThrowError ( AssertionError )
313
- . toHaveMessage ( "Expected element <View ... /> NOT to contain element <Text ... />." ) ;
314
- expect ( ( ) => parentElementAssertion . toContainElement ( text ) )
328
+ expect ( ( ) => textElementAssertion . toContainElement ( parent ) )
315
329
. toThrowError ( AssertionError )
316
- . toHaveMessage ( "Expected element <View ... /> to contain element <Text ... />." ) ;
330
+ . toHaveMessage ( "Expected element <Text ... /> to contain element <View ... />." ) ;
317
331
} ) ;
318
332
} ) ;
319
333
} ) ;
0 commit comments