Detox uses Matchers to find UI elements
in your app, Actions to emulate user interaction with those elements
and Expectations to verify values on those elements
.
Expect verifies if a certain value is as expected to be.
.toBeVisible()
.toBeNotVisible()
.toExist()
.toNotExist()
.toHaveText()
.toHaveLabel()
.toHaveId()
.toHaveValue()
Expect the view to be at least 75% visible.
await expect(element(by.id('UniqueId204'))).toBeVisible();
Expect the view to not be visible.
await expect(element(by.id('UniqueId205'))).toBeNotVisible();
Expect the view to exist in the UI hierarchy.
await expect(element(by.id('UniqueId205'))).toExist();
Expect the view to not exist in the UI hierarchy.
await expect(element(by.id('RandomJunk959'))).toNotExist();
-
In React Native apps, expect UI component of type
<Text>
to have text. -
In native iOS apps, expect UI elements of type UIButton, UILabel, UITextField or UITextViewIn to have inputText with text.
await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text');
-
It searches by accessibilityLabel on iOS, or by contentDescription on Android.
-
In React Native it can be set for both platforms by defining an
accessibilityLabel
on the view.
await expect(element(by.id('UniqueId204'))).toHaveLabel('Done');
- In React Native apps, expect UI component to have
testID
with that id. - In native iOS apps, expect UI element to have accesibilityIdentifier with that id.
await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204');
Expect components like a Switch to have a value ('0' for off, '1' for on).
await expect(element(by.id('UniqueId533'))).toHaveValue('0');