@@ -330,32 +330,46 @@ describe("[Unit] ElementAssertion.test.ts", () => {
330
330
const parentElementAssertion = new ElementAssertion ( parent ) ;
331
331
const child = element . getByTestId ( "childId" ) ;
332
332
const text = element . getByTestId ( "textId" ) ;
333
+ const textElementAssertion = new ElementAssertion ( text ) ;
333
334
334
- context ( "when the container element contains the target element" , ( ) => {
335
- it ( "returns the assertion instance" , ( ) => {
336
- expect ( containerElementAssertion . toContainElement ( parent ) ) . toBe ( containerElementAssertion ) ;
337
- expect ( containerElementAssertion . toContainElement ( child ) ) . toBe ( containerElementAssertion ) ;
338
- expect ( containerElementAssertion . toContainElement ( text ) ) . toBe ( containerElementAssertion ) ;
339
- expect ( parentElementAssertion . toContainElement ( child ) ) . toBe ( parentElementAssertion ) ;
335
+ context ( "when the element has children" , ( ) => {
336
+ context ( "and the target element is found in the children's element" , ( ) => {
337
+ it ( "returns the assertion instance" , ( ) => {
338
+ expect ( containerElementAssertion . toContainElement ( parent ) ) . toBe ( containerElementAssertion ) ;
339
+ expect ( containerElementAssertion . toContainElement ( child ) ) . toBe ( containerElementAssertion ) ;
340
+ expect ( containerElementAssertion . toContainElement ( text ) ) . toBe ( containerElementAssertion ) ;
341
+ expect ( parentElementAssertion . toContainElement ( child ) ) . toBe ( parentElementAssertion ) ;
342
+ } ) ;
343
+
344
+ it ( "throws an error for negative assertion" , ( ) => {
345
+ expect ( ( ) => containerElementAssertion . not . toContainElement ( parent ) )
346
+ . toThrowError ( AssertionError )
347
+ . toHaveMessage ( "Expected element <View ... /> NOT to contain element <View ... />." ) ;
348
+ expect ( ( ) => containerElementAssertion . not . toContainElement ( text ) )
349
+ . toThrowError ( AssertionError )
350
+ . toHaveMessage ( "Expected element <View ... /> NOT to contain element <Text ... />." ) ;
351
+ } ) ;
340
352
} ) ;
341
353
342
- it ( "returns the assertion instance for negated assertions when the target element is not contained" , ( ) => {
343
- expect ( parentElementAssertion . not . toContainElement ( text ) ) . toBeEqual ( parentElementAssertion ) ;
344
- expect ( parentElementAssertion . not . toContainElement ( container ) ) . toBeEqual ( parentElementAssertion ) ;
354
+ context ( "and the target element is NOT found in the children's element" , ( ) => {
355
+ it ( "throws an error" , ( ) => {
356
+ expect ( ( ) => parentElementAssertion . toContainElement ( text ) )
357
+ . toThrowError ( AssertionError )
358
+ . toHaveMessage ( "Expected element <View ... /> to contain element <Text ... />." ) ;
359
+ } ) ;
360
+
361
+ it ( "returns the assertion instance for negative assertion" , ( ) => {
362
+ expect ( parentElementAssertion . not . toContainElement ( text ) ) . toBeEqual ( parentElementAssertion ) ;
363
+ expect ( parentElementAssertion . not . toContainElement ( container ) ) . toBeEqual ( parentElementAssertion ) ;
364
+ } ) ;
345
365
} ) ;
346
366
} ) ;
347
367
348
- context ( "when the container element does NOT contain the target element " , ( ) => {
368
+ context ( "when the element does NOT have children " , ( ) => {
349
369
it ( "throws an error" , ( ) => {
350
- expect ( ( ) => containerElementAssertion . not . toContainElement ( parent ) )
351
- . toThrowError ( AssertionError )
352
- . toHaveMessage ( "Expected element <View ... /> NOT to contain element <View ... />." ) ;
353
- expect ( ( ) => containerElementAssertion . not . toContainElement ( text ) )
354
- . toThrowError ( AssertionError )
355
- . toHaveMessage ( "Expected element <View ... /> NOT to contain element <Text ... />." ) ;
356
- expect ( ( ) => parentElementAssertion . toContainElement ( text ) )
370
+ expect ( ( ) => textElementAssertion . toContainElement ( parent ) )
357
371
. toThrowError ( AssertionError )
358
- . toHaveMessage ( "Expected element <View ... /> to contain element <Text ... />." ) ;
372
+ . toHaveMessage ( "Expected element <Text ... /> to contain element <View ... />." ) ;
359
373
} ) ;
360
374
} ) ;
361
375
} ) ;
0 commit comments