Skip to content

Commit 2e2fdff

Browse files
thiagobrezmdjastrzebski
authored andcommitted
chore: detect Modal as host component
1 parent 5a634db commit 2e2fdff

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type HostComponentNames = {
2424
text: string;
2525
textInput: string;
2626
switch: string;
27+
modal: string;
2728
};
2829

2930
export type InternalConfig = Config & {

src/helpers/host-component-names.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { ReactTestInstance } from 'react-test-renderer';
3-
import { Switch, Text, TextInput, View } from 'react-native';
3+
import { Modal, Switch, Text, TextInput, View } from 'react-native';
44
import { configureInternal, getConfig, HostComponentNames } from '../config';
55
import { renderWithAct } from '../render-act';
66
import { HostTestInstance } from './component-tree';
@@ -35,13 +35,15 @@ function detectHostComponentNames(): HostComponentNames {
3535
<Text testID="text">Hello</Text>
3636
<TextInput testID="textInput" />
3737
<Switch testID="switch" />
38+
<Modal testID="modal" />
3839
</View>
3940
);
4041

4142
return {
4243
text: getByTestId(renderer.root, 'text').type as string,
4344
textInput: getByTestId(renderer.root, 'textInput').type as string,
4445
switch: getByTestId(renderer.root, 'switch').type as string,
46+
modal: getByTestId(renderer.root, 'modal').type as string,
4547
};
4648
} catch (error) {
4749
const errorMessage =
@@ -86,3 +88,13 @@ export function isHostTextInput(
8688
): element is HostTestInstance {
8789
return element?.type === getHostComponentNames().textInput;
8890
}
91+
92+
/**
93+
* Checks if the given element is a host Modal.
94+
* @param element The element to check.
95+
*/
96+
export function isHostModal(
97+
element?: ReactTestInstance | null
98+
): element is HostTestInstance {
99+
return element?.type === getHostComponentNames().modal;
100+
}

src/matchers/to-be-visible.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ReactTestInstance } from 'react-test-renderer';
22
import { matcherHint } from 'jest-matcher-utils';
33
import { StyleSheet } from 'react-native';
44
import { getHostParent } from '../helpers/component-tree';
5+
import { isHostModal } from '../helpers/host-component-names';
56
import { checkHostElement, formatElement } from './utils';
67

78
function isVisibleForStyles(element: ReactTestInstance) {
@@ -19,7 +20,7 @@ function isVisibleForAccessibility(element: ReactTestInstance) {
1920
}
2021

2122
function isModalVisible(element: ReactTestInstance) {
22-
return element.type.toString() !== 'Modal' || element.props.visible !== false;
23+
return !isHostModal(element) || element.props.visible !== false;
2324
}
2425

2526
function isElementVisible(element: ReactTestInstance): boolean {

0 commit comments

Comments
 (0)