-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 = () => { |
There was a problem hiding this comment.
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 😬
const SimpleToggleText: React.FC = () => { | |
function SimpleToggleText(): ReactElement { |
const [isVisible, setIsVisible] = useState(true); | ||
|
||
const handleToggle = useCallback((): void => { | ||
setIsVisible((prev: boolean) => !prev); |
There was a problem hiding this comment.
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 🙂
setIsVisible((prev: boolean) => !prev); | |
setIsVisible(prev => !prev); |
return ( | ||
<View> | ||
<Text | ||
testID="textElement" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
const element = render( | ||
<Modal testID="id" visible={true} />, | ||
); |
There was a problem hiding this comment.
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 🙂
const element = render( | |
<Modal testID="id" visible={true} />, | |
); | |
const { getByTestId } = render( | |
<Modal testID="id" visible={true} />, | |
); |
35e5052
to
82fa78b
Compare
This PR adds the
toBeVisible
matcher for React Native