test(to-contain-element): validate container contains child element

This commit is contained in:
Maciej Jastrzębski
2026-01-08 23:48:47 +01:00
parent 40ad3245a8
commit af873192ce
2 changed files with 20 additions and 0 deletions
@@ -0,0 +1,19 @@
import * as React from 'react';
import { Text, View } from 'react-native';
import { render, screen } from '../..';
it('checks if container element contains child element', async () => {
const Component = () => (
<View testID="container">
<Text testID="child">Child content</Text>
</View>
);
await render(<Component />);
const container = screen.getByTestId('container');
const child = screen.getByTestId('child');
expect(container).toContainElement(child);
});
+1
View File
@@ -13,3 +13,4 @@ test(fire-event): Validates fireEvent.press invokes event handler on element - c
test(matchers/to-be-visible): Validates toBeVisible matcher correctly identifies visible elements - critical matcher users depend on for testing UI visibility state. Coverage: 77.04% statements (was 21.31%), 50% branches, 75% functions for to-be-visible.ts. Covered main matcher function, isElementVisible core logic, parent traversal. Uncovered: error message formatting, hidden-from-accessibility edge cases, style-based hiding (opacity/display), modal visibility check.
test(matchers/to-have-prop): Validates toHaveProp matcher checks element props with optional value matching - critical matcher users depend on for verifying component props. Coverage: 49.09% statements (was 12.72%), 100% branches, 33.33% functions for to-have-prop.ts. Covered main matcher function, prop existence check, value comparison. Uncovered: error message formatting (lines 25-41), formatProp helper (lines 45-55).
test(matchers/to-be-disabled): Validates toBeDisabled and toBeEnabled matchers check element disabled state via accessibilityState - critical matcher users depend on for testing disabled/enabled UI states. Coverage: 70.37% statements (was 22.22%), 83.33% branches, 60% functions for to-be-disabled.ts. Covered main matcher functions, computeAriaDisabled logic, both matchers. Uncovered: error message formatting (lines 17-24, 36-43).
test(matchers/to-contain-element): Validates toContainElement matcher checks if container element contains child element - critical matcher users depend on for testing component hierarchies and element relationships. Coverage: 75.67% statements (was 21.62%), 100% branches, 50% functions for to-contain-element.ts. Covered main matcher function, element containment check via queryAll. Uncovered: error message formatting (lines 27-35).