Skip to content

Latest commit

 

History

History
127 lines (83 loc) · 3.8 KB

APIRef.Expect.md

File metadata and controls

127 lines (83 loc) · 3.8 KB

Expect

Detox uses matchers to match UI elements in your app and expectations to verify those elements are in the expected state.

Use actions to simulate use interaction with elements.

Methods

toBeVisible()

Expects the element to be visible on screen.

On iOS, visibility is defined by having the view, or one of its subviews, be topmost at the view's activation point on screen.

await expect(element(by.id('UniqueId204'))).toBeVisible();

toExist()

Expects the element to exist within the app’s current UI hierarchy.

await expect(element(by.id('UniqueId205'))).toExist();

toHaveText(text)

Expects the element to have the specified text.

await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text');

toHaveLabel(label)

Expects the element to have the specified label as its accessibility label (iOS) or content description (Android). In React Native, this corresponds to the value in the accessibilityLabel prop.

await expect(element(by.id('UniqueId204'))).toHaveLabel('Done');

toHaveId(id)

Expects the element to have the specified accessibility identifier. In React Native, this corresponds to the value in the testID prop.

await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204');

toHaveValue(value)

Expects the element to have the specified accessibility value. In React Native, this corresponds to the value in the accessibilityValue prop.

await expect(element(by.id('UniqueId533'))).toHaveValue('0');

toHaveSliderPosition(normalizedPosition, tolerance) iOS only

Expects the slider element to have the specified normalized position ([0, 1]), within the provided tolerance (optional).

await expect(element(by.id('slider'))).toHaveSliderPosition(0.75);
await expect(element(by.id('slider'))).toHaveSliderPosition(0.3113, 0.00001);

toHaveToggleValue(value)

Expects a toggle-able element (e.g. a Switch or a Check-Box) to be on/checked or off/unchecked. As a reference, in react-native, this is the equivalent switch component.

await expect(element(by.id('switch'))).toHaveToggleValue(true);
await expect(element(by.id('checkbox'))).toHaveToggleValue(false);

not

Negates the expectation.

await expect(element(by.id('UniqueId533'))).not.toBeVisible();

withTimeout(timeout)

Waits until the expectation is resolved for the specified amount of time. If timeout is reached before resolution, the expectation is failed.

timeout—the timeout to wait, in ms

await waitFor(element(by.id('UniqueId204'))).toBeVisible().withTimeout(2000);

Deprecated Methods

toBeNotVisible()

Deprecated: Use .not.toBeVisible() instead.

Expects the element to not be visible on screen.

await expect(element(by.id('UniqueId205'))).toBeNotVisible();

toNotExist()

Deprecated: Use .not.toExist() instead.

Expects the element to not exist within the app’s current UI hierarchy.

await expect(element(by.id('RandomJunk959'))).toNotExist();