Skip to content

Commit

Permalink
Publish docs version 20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile1-internal committed Mar 22, 2023
1 parent 03e23e7 commit 9c4cafb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion website/versioned_docs/version-20.x/api/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Returns an object, representing various attributes of the element.
Retrieved attributes are:

- `text`: The text value of any textual element.
- `label`: The label of the element. Matches `accessibilityLabel` for iOS, and `contentDescription` for android.
- `label`: The label of the element. Matches `accessibilityLabel` for iOS, and `contentDescription` for android. Refer to the [`.toHaveLabel()` API](./expect.md#tohavelabellabel) in order to learn about caveats associated with this attribute in React Native apps.
- `placeholder`: The placeholder text value of the element. Matches `hint` on android.
- `enabled`: Whether the element is enabled for user interaction.
- `identifier`: The identifier of the element. Matches `accessibilityIdentifier` on iOS, and the main view tag, on Android - both commonly **holding the component’s test ID in React Native apps**.
Expand Down
42 changes: 27 additions & 15 deletions website/versioned_docs/version-20.x/api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,60 +28,72 @@ Negating this expectation with a `not` expression expects the view’s visible a
On iOS, visibility is defined by having the view, or one of its subviews, be topmost at the view’s activation point on screen.

```js
await expect(element(by.id('UniqueId203'))).toBeVisible();
await expect(element(by.id('UniqueId204'))).toBeVisible(35);
await expect(element(by.id('subtitle'))).toBeVisible();
await expect(element(by.id('mainTitle'))).toBeVisible(35);
```

### `toExist()`

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

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

### `toBeFocused()`

Expects the element to be the focused element.

```js
await expect(element(by.id('textFieldId'))).toBeFocused();
await expect(element(by.id('emailInput'))).toBeFocused();
```

### `toHaveText(text)`

Expects the element to have the specified text.

```js
await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text');
await expect(element(by.id('mainTitle'))).toHaveText('Welcome back!');
```

### `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`](https://reactnative.dev/docs/accessibility#accessibilitylabel) prop.

:::note
Note that there is an inconsistency between the implementation for accessibility between Android and iOS. On iOS if a View has no `accessibilityLabel` explicitly defined, then it defaults to having a concatenation of the accessibilityLabels of the child Views. On Android, the same View would have no `accessibilityLabel` at all. See [this](https://github.com/facebook/react-native/issues/32826) issue for details.
Note that in React Native apps, the `accessibilityLabel` is computed in a non-standard way, which happens to [differ between iOS and Android](https://github.com/facebook/react-native/issues/32826). Detox [bridges over that gap](https://github.com/wix/Detox/issues/3977) by artificially aligning Android to iOS.
Effectively, that means that in React Native apps, performing accessibility-label based matching for elements **with no explicit label** suggests that the matching will be performed against a concatenation of labels from the child-elements, if applicable. For example:

```js
<View testID='title-root'>
<Text accessibilityLabel={'title'}>Goodbye!</Text>
<Text accessibilityLabel={'subtitle'}>Thanks for all the fish.</Text>
</View>
```

In this case, where `title-root` has no accessibility label of its own, matching the label of `title-root` will be performed against the text: `title subtitle`.

Also note that in iOS, `accessibilityLabel` for primitive elements such as text, automatically receives the text itself - even if the accessibilityLabel prop isn't explicitly specified.
:::

```js
await expect(element(by.id('UniqueId204'))).toHaveLabel('Done');
await expect(element(by.id('submitButton'))).toHaveLabel('Submit');
```

### `toHaveId(id)`

Expects the element to have the specified accessibility identifier. In React Native, this corresponds to the value in the [`testID`](https://reactnative.dev/docs/view.html#testid) prop.

```js
await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204');
await expect(element(by.text('Submit'))).toHaveId('submitButton');
```

### `toHaveValue(value)`

Expects the element to have the specified accessibility value. In React Native, this corresponds to the value in the [`accessibilityValue`](https://reactnative.dev/docs/view.html#accessibilityvalue) prop.

```js
await expect(element(by.id('UniqueId533'))).toHaveValue('0');
await expect(element(by.id('temperatureDial'))).toHaveValue('25');
```

### `toHaveSliderPosition(normalizedPosition, tolerance)`
Expand Down Expand Up @@ -109,7 +121,7 @@ Waits until the expectation is resolved for the specified amount of time. If tim
`timeout`—the timeout to wait, in ms

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

## Properties
Expand All @@ -119,9 +131,9 @@ await waitFor(element(by.id('UniqueId204'))).toBeVisible().withTimeout(2000);
Negates the expectation, e.g.:

```js
await expect(element(by.id('UniqueId533'))).not.toBeVisible();
await expect(element(by.id('UniqueId533'))).not.toExist();
await expect(element(by.id('UniqueId533'))).not.toBeFocused();
await expect(element(by.id('UniqueId533'))).not.toHaveText('');
await expect(element(by.id('UniqueId533'))).not.toHaveValue('');
await expect(element(by.id('tinyButton'))).not.toBeVisible();
await expect(element(by.id('tinyButton'))).not.toExist();
await expect(element(by.id('tinyButton'))).not.toBeFocused();
await expect(element(by.id('tinyButton'))).not.toHaveText('');
await expect(element(by.id('tinyButton'))).not.toHaveValue('');
```

0 comments on commit 9c4cafb

Please sign in to comment.