Skip to content

Commit 9e09cc9

Browse files
committed
Review docs
1 parent 85f172a commit 9e09cc9

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

docs/API.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,11 @@ await expect(browser).toHaveClipboardText(expect.stringContaining('clipboard tex
256256

257257
### Multiples Elements Support
258258

259-
All element matchers work with arrays of elements (e.g., `$$()` results).
260-
- In short, matchers is applied on each elements and must pass for the entire assertion to succeed, so if one fails, the assertions fails.
261-
- See [MutipleElements.md](MultipleElements.md) for more information.
259+
All element matchers support arrays (e.g., `$$()` results).
260+
261+
- Each element must pass the matcher for the assertion to succeed; if any fail, the assertion fails.
262+
- `toHaveText` differ and keep it's legacy behavior.
263+
- See [MultipleElements.md](MultipleElements.md) for details.
262264

263265
#### Usage
264266

@@ -270,16 +272,20 @@ await expect(await $$('#someElem')).toBeDisplayed()
270272
```ts
271273
const elements = await $$('#someElem')
272274

273-
// Single expected value compare with each element's value
275+
// Single value: checked against every element
274276
await expect(elements).toHaveAttribute('class', 'form-control')
275277

276-
// Multiple expected values for exactly 2 elements having exactly 'control1' & 'control2' as values
278+
// Array: each value checked at corresponding element index (must match length)
277279
await expect(elements).toHaveAttribute('class', ['control1', 'control2'])
278280

279-
// Multiple expected values for exactly 2 elements but with more flexibility for the first element's value
281+
// Use asymmetric matchers for flexible matching
280282
await expect(elements).toHaveAttribute('class', [expect.stringContaining('control1'), 'control2'])
281283

282-
// Filtered array also works
284+
// Use RegEx `i` for case insensitive
285+
await expect(elements).toHaveAttribute('class', [/'Control1'/i, 'control2'])
286+
287+
288+
// Works with filtered arrays too
283289
await expect($$('#someElem').filter(el => el.isDisplayed())).toHaveAttribute('class', ['control1', 'control2'])
284290
```
285291

docs/MultipleElements.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
# Multiple Elements Support
22

3-
All element matchers work with arrays of elements (e.g., `$$()` results).
4-
- **Strict Length Matching**: If you provide an array of expected values, the number of values must match the number of elements found. A failure occurs if the lengths differ.
5-
- **Index-based Matching**: When using an array of expected values, each element is compared to the value at the corresponding index.
6-
- **Single Value Matching**: If you provide a single expected value, it is compared against *every* element in the array.
7-
- **Asymmetric Matchers**: Asymmetric matchers can be used within the expected values array for more matching flexibility.
8-
- If no elements exist, a failure occurs (except with `toBeElementsArrayOfSize`).
9-
- Options like `StringOptions` or `HTMLOptions` apply to the entire array (except `NumberOptions`).
10-
- The assertion passes only if **all** elements match the expected value(s).
11-
- Using `.not` applies the negation to each element (e.g., *all* elements must *not* display).
3+
Matchers element array support (e.g., `$$()`):
124

13-
**Note:** Strict length matching does not apply on `toHaveText` to preserve existing behavior.
5+
- **Strict Index-based Matching**: If an array of expected values is provided, it must match the elements' count; each value is checked at its index.
6+
- If a single value is provided, every element is compared to it.
7+
- Asymmetric matchers (e.g., `expect.stringContaining`) work within expected value arrays.
8+
- An error is thrown if no elements are found (except with `toBeElementsArrayOfSize`).
9+
- Options like `StringOptions` or `HTMLOptions` apply to the whole array; `NumberOptions` behaves like any expected provided value.
10+
- The assertion passes only if **all** elements match.
11+
- Using `.not` means all elements must **not** match.
12+
13+
**Note:** Strict Index-based matching does not apply to `toHaveText`, since an existing behavior was already in placed.
1414

1515
## Limitations
16-
- An alternative to using `StringOptions` (like `ignoreCase` or `containing`) for a single expected value is to use RegEx (`/MyExample/i`) or Asymmetric Matchers (`expect.stringContaining('Example')`).
17-
- Passing an array of "containing" values, as previously supported by `toHaveText`, is deprecated and not supported for other matchers.
16+
- Instead of `StringOptions` for a single expected value, use RegExp or asymmetric matchers.
17+
- For `ignoreCase` use RegEx (`/MyExample/i`)
18+
- For `containing` use Asymmetric Matchers (`expect.stringContaining('Example')`)
19+
- Passing an array of "containing" values is deprecated and not supported outside `toHaveText`.
1820

1921
## Supported types
20-
21-
Any of the below element types can be passed to `expect`:
22+
You can pass any of these element types to `expect`:
2223
- `ChainablePromiseArray` (the non-awaited case)
2324
- `ElementArray` (the awaited case)
2425
- `Element[]` (the filtered case)
2526

2627
## Alternative
2728

28-
For better control on each element value assertion, a parametrized test of your assertion framework can be used.
29-
Example with mocha
29+
For more granular or explicit per-element validation, use a parameterized test of your framework.
30+
Example in Mocha:
3031
```ts
3132
describe('Element at index of `$$`', function () {
3233
[ { expectedText: 'one', index: 0 },

0 commit comments

Comments
 (0)