feat: support arrayContaining in toHaveText - #2211
dprevost-LMI merged 3 commits into
Conversation
Greptile SummaryThis PR adds collection-level
Confidence Score: 5/5The PR appears safe to merge, with the previously reported retry, concurrency, and framework type-coverage issues resolved. The shared executor preserves retry and negation contracts, refreshes selector-backed collections, terminates static invalid inputs, reads collection values concurrently, and retains raw getter values for whole-snapshot matching. No actionable new defect or outstanding previous finding remains.
|
| Filename | Overview |
|---|---|
| src/util/executeCommand.ts | Centralizes collection snapshot extraction, concurrent value reads, refetch behavior, and asymmetric comparison for opted-in matchers. |
| src/utils.ts | Adds protocol-based recognition for Jest/WebdriverIO and Jasmine array-containing matchers. |
| src/jasmineUtils.ts | Supplies Jasmine-compatible containment semantics for nested collection matching. |
| src/matchers/element/toHaveText.ts | Migrates toHaveText collection matching to the shared executor and preserves terminal validation behavior. |
| src/matchers/element/toHaveElementProperty.ts | Enables collection subset matching while retaining scalar array-valued property assertions. |
| types/expect-webdriverio.d.ts | Extends the Jasmine asymmetric matcher protocol to accept its optional pretty-printer. |
| test/matchers/element/arrayContaining.test.ts | Covers collection subset behavior across value matchers, aliases, options, nested matchers, and scalar properties. |
| test/matchers/element/toHaveText.test.ts | Exercises terminal failures, concurrent reads, refetching, retries, negation, diagnostics, and matcher reuse. |
| docs/API.md | Documents supported matchers, collection semantics, retries, options, and Jasmine compatibility. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Element collection] --> B[Shared command executor]
B --> C[Resolve or refresh elements]
C --> D[Read values concurrently]
D --> E[Build ordered value snapshot]
E --> F[Apply arrayContaining once]
F --> G{Assertion passes?}
G -->|Yes| H[Return assertion result]
G -->|No, retryable| C
G -->|No, terminal| H
Reviews (3): Last reviewed commit: "feat: centralize arrayContaining across ..." | Re-trigger Greptile
|
@greptile, could this be extended to all matchers instead of just toHaveText? |
|
Yes, but I’d generalize the execution strategy rather than duplicate the
A good follow-up would add a generic collection-comparison path that:
That could cover array-valued matchers such as So yes—this is a sensible abstraction, but I’d keep this PR focused and extract the shared collection strategy in a follow-up. The shared implementation should also detect the asymmetric matcher through a utility rather than relying on the |
|
@greptile, instead of doing a double implementation, why not do one centralized implementation for all matchers? Can you propose a solution?
|
|
Yes. I’d move this into Extend
The same option can be supplied by I’d add This gives us one centralized implementation without making the common strategy aware of |
|
@dprevost-LMI |
|
@JustasMonkev, that would be preferable if you are open to it! |
Gotcha, thanks for clearing it up. I’ll handle it tomorrow. |
BTW, FYI, if you need similar behaviour in the short term, potentially |
Thanks for the tip! I’ve pushed the centralized implementation in da6960d. This also covers the case where both values must be present, with extra elements allowed. @dprevost-LMI |
|
Should I do anything else? |
|
No, I'm just swamped |
Adds
arrayContaining()support totoHaveText()with$$().Works with extra elements, any order, nested matchers,
.not, and retries.Closes #2004.