Skip to content

feat(native): Add toBeVisible #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kdquistanchala
Copy link
Contributor

This PR adds the toBeVisible matcher for React Native

@kdquistanchala kdquistanchala changed the base branch from main to feat/native-to-be-empty March 21, 2025 22:13
@kdquistanchala kdquistanchala self-assigned this Mar 24, 2025
@kdquistanchala kdquistanchala added the enhancement New feature or request label Mar 24, 2025
@kdquistanchala kdquistanchala requested a review from suany0805 April 3, 2025 21:15
Copy link
Member

@JoseLion JoseLion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far! I left a few suggestion, let me know if you have any question 🙂

} from "react-native";

import { ElementAssertion } from "../../src/lib/ElementAssertion";

const SimpleToggleText: React.FC = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using the React.FC type, as its function return type is too broad. A named function is usually a better choice, as it also gets hoisted 😬

Suggested change
const SimpleToggleText: React.FC = () => {
function SimpleToggleText(): ReactElement {

const [isVisible, setIsVisible] = useState(true);

const handleToggle = useCallback((): void => {
setIsVisible((prev: boolean) => !prev);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It's ok to let TS infer the type of callback arguments 🙂

Suggested change
setIsVisible((prev: boolean) => !prev);
setIsVisible(prev => !prev);

return (
<View>
<Text
testID="textElement"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the testId should be our last resort to query elements. For instance, this element can be found using a getByText("Toggle me!") query.

{"Toggle me!"}
</Text>
<Button
testID="toggleButton"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same on this one. The byRole query is preferred in most cases, and for this element, we should be able to do getByRole("button", { name: "Toggle Text" }) instead.

Comment on lines 194 to 196
const element = render(
<Modal testID="id" visible={true} />,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Destructuring can help make the queries simpler 🙂

Suggested change
const element = render(
<Modal testID="id" visible={true} />,
);
const { getByTestId } = render(
<Modal testID="id" visible={true} />,
);

Base automatically changed from feat/native-to-be-empty to main April 25, 2025 17:51
@kdquistanchala kdquistanchala force-pushed the feat/native-to-be-visible branch from 35e5052 to 82fa78b Compare April 25, 2025 18:41
@kdquistanchala kdquistanchala requested a review from JoseLion April 25, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants