Skip to content

fix: Align Jasmine typing + support jasmine asymetrics matchers + other types fixes#2018

Draft
dprevost-LMI wants to merge 52 commits into
webdriverio:mainfrom
dprevost-LMI:use-expect-async-matchers-with-jasmine
Draft

fix: Align Jasmine typing + support jasmine asymetrics matchers + other types fixes#2018
dprevost-LMI wants to merge 52 commits into
webdriverio:mainfrom
dprevost-LMI:use-expect-async-matchers-with-jasmine

Conversation

@dprevost-LMI

@dprevost-LMI dprevost-LMI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #1893
Fixes #1407 for real

Highlights:

  • jasmine-expect-global.test-d provides proper Jasmine typing to use expect asynchronously with wdio/jasmine-framework
    • withContext is support for sync & async matchers
    • sync matchers are also async, following the hack of adding all sync matchers on expect forced to be expectAsync
    • Later to move into wdio/jasmine-framework
  • jasmine.stringContaining now working with any text-based wdio matcher

TODOs

  • Check and/or document if supporting Jasmine asymetrics matcher under expec-wdio import is needed

Waiting

@christian-bromann

Copy link
Copy Markdown
Member

@dprevost-LMI thanks for this effort, let me know the status of this and when I can review.

@dprevost-LMI dprevost-LMI force-pushed the use-expect-async-matchers-with-jasmine branch from 8ac2038 to 4648bd6 Compare March 8, 2026 15:59
Comment thread playgrounds/jest/jest.setup.after-env.ts Outdated
@dprevost-LMI dprevost-LMI force-pushed the use-expect-async-matchers-with-jasmine branch from 34cb319 to b864314 Compare March 8, 2026 17:59
@dprevost-LMI dprevost-LMI force-pushed the use-expect-async-matchers-with-jasmine branch from b864314 to 5bb0b0c Compare March 14, 2026 12:28
@dprevost-LMI

Copy link
Copy Markdown
Contributor Author

@dprevost-LMI thanks for this effort, let me know the status of this and when I can review.

@christian-bromann I reviewed it thoroughly following the latest release and ensured it works with the latest wdio, so it's fully ready for you to review!

@dprevost-LMI dprevost-LMI marked this pull request as ready for review March 14, 2026 19:19
@dprevost-LMI dprevost-LMI marked this pull request as draft April 5, 2026 16:29
@dprevost-LMI dprevost-LMI marked this pull request as ready for review April 5, 2026 21:51
@dprevost-LMI dprevost-LMI marked this pull request as draft May 3, 2026 12:42
@dprevost-LMI dprevost-LMI force-pushed the use-expect-async-matchers-with-jasmine branch from b129c66 to fa34827 Compare June 7, 2026 15:39
@dprevost-LMI dprevost-LMI marked this pull request as ready for review June 8, 2026 14:38
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR aligns the Jasmine framework typing with the actual runtime behavior of @wdio/jasmine-framework, adds support for Jasmine asymmetric matchers (e.g. jasmine.stringContaining) in WDIO matchers, and resolves a large number of previously suppressed @ts-expect-error comments across the Jasmine playground and type-test files.

  • src/utils.ts: Removes the $$typeof Symbol check from isAsymmetricMatcher, adds isJasmineAsymmetricMatcher, isStringContainingMatcherLike, isStrictlyStringContainingMatcher, and getAsymmetricMatcherValue to unify Wdio and Jasmine matcher handling; compareText updated to use the new helpers, but compareTextWithArray still accesses .sample directly in its ignoreCase branch.
  • jasmine-wdio-expect-async.d.ts: Introduces JasmineExpect, JasmineSyncMatchers, and withContext chaining so the global expect under @wdio/jasmine-framework is correctly typed as fully asynchronous.
  • playgrounds/package-lock.json: The node_modules/jest-diff lock entry is corrupted — its resolved URL and integrity now point to jest-changed-files, which will break npm ci in the playground.

Confidence Score: 3/5

The runtime logic change in compareTextWithArray leaves Jasmine StringContaining matchers broken under ignoreCase, and the playground lock file is corrupted in a way that would install the wrong npm package.

Two independent defects are introduced: compareTextWithArray silently uses undefined as the matcher sample for any Jasmine StringContaining in the array when ignoreCase: true, and the playground package-lock.json maps jest-diff to the jest-changed-files tarball, causing a broken install. Both need to be fixed before merging.

src/utils.ts (the compareTextWithArray ignoreCase branch) and playgrounds/package-lock.json (the node_modules/jest-diff entry) need attention before this is merged.

Important Files Changed

Filename Overview
src/utils.ts Adds Jasmine asymmetric matcher support via new helper functions; compareText updated correctly, but compareTextWithArray still accesses .sample directly for the ignoreCase path, breaking Jasmine matchers in array comparisons.
jasmine-wdio-expect-async.d.ts Adds JasmineExpect interface, JasmineSyncMatchers mapped type, and withContext support; correctly replaces old Expect augmentation with the new Jasmine-specific type structure.
jasmine.d.ts Simplified to only augment AsyncMatchers with WDIO custom matchers; snapshot matcher overrides removed.
types/expect-webdriverio.d.ts Adds JasmineAsymmetricMatcher<R> global type; separates Matchers from ExpectLibMatchers in MatchersAndInverse to prevent Jest-only matchers from bleeding into the Jasmine augmentation.
playgrounds/package-lock.json Corrupted lock file: the node_modules/jest-diff entry now resolves to the jest-changed-files package URL/integrity, breaking npm ci in the playground.
types-checks-filter-out-node_modules.js Suppresses TS2304 for unresolved Expected<T> type; silences a genuine consumer-visible gap rather than fixing the underlying type reference.
test/utils.test.ts Adds comprehensive unit tests for new asymmetric-matcher utility functions using a mock Jasmine StringContaining class.
test-types/jasmine-global-expect-async/jasmine-expect-global.test-d.ts Uncomments all previously-skipped type tests for the Jasmine global expect; adds coverage for withContext, promise matchers, and asymmetric matchers.
playgrounds/mocha/wdio.conf.ts Adds four commented-out spec globs that appear to be leftover development artifacts.
playgrounds/jasmine/test/specs/expect-wdioImport/network-matchers.test.ts New playground test for network matchers with Jasmine and expect asymmetric matchers; last it block has cosmetic 8-space indent instead of 4.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[asymmetric matcher passed to compareText / compareTextWithArray] --> B{isAsymmetricMatcher?}
    B -- No --> C[string / RegExp path]
    B -- Yes --> D{isStringContainingMatcherLike?}
    D -- Yes, ignoreCase --> E{isWdioAsymmetricMatcher?}
    E -- Yes: Wdio --> F[getAsymmetricMatcherValue → .sample]
    E -- No: Jasmine --> G[getAsymmetricMatcherValue → .expected]
    F --> H[isStrictlyStringContainingMatcher?]
    G --> H
    H -- Yes --> I[expect.stringContaining lower]
    H -- No --> J[expect.not.stringContaining lower]
    D -- No --> K[asymmetricMatch directly]
    I --> K
    J --> K
    subgraph BUG in compareTextWithArray
        L[item in expectedArray] --> M{isStringContainingMatcherLike?}
        M -- Yes --> N[item.sample?.toString - undefined for Jasmine!]
    end
Loading

Comments Outside Diff (5)

  1. src/utils.ts, line 276-282 (link)

    P1 compareTextWithArray still uses .sample instead of getAsymmetricMatcherValue

    compareText was updated to call getAsymmetricMatcherValue to support both Wdio (sample) and Jasmine (expected) matchers under ignoreCase. However, the parallel ignoreCase branch in compareTextWithArray was NOT updated and still accesses item.sample?.toString() directly. For any Jasmine StringContaining matcher passed in an array (which uses .expected, not .sample), item.sample is undefined, so expect.stringContaining(undefined) is called, producing silent incorrect results instead of a case-folded match.

  2. src/utils.ts, line 276-280 (link)

    P1 Use getAsymmetricMatcherValue here, consistent with compareText, to correctly extract the sample value from both Wdio (.sample) and Jasmine (.expected) matchers. The current item.sample?.toString() call returns undefined for Jasmine matchers, causing expect.stringContaining(undefined) to be created silently.

  3. playgrounds/package-lock.json, line 7988-8003 (link)

    P1 node_modules/jest-diff entry resolves to the wrong package

    The node_modules/jest-diff entry's resolved URL and integrity now point to jest-changed-files instead of jest-diff, and its dependencies are jest-changed-files's (execa, jest-util, p-limit) rather than jest-diff's (@jest/diff-sequences, chalk, pretty-format). Running npm ci in the playgrounds directory will install jest-changed-files under the node_modules/jest-diff path, breaking jest-matcher-utils and any other package that imports from jest-diff. The lock file should be regenerated from a clean state.

  4. playgrounds/mocha/wdio.conf.ts, line 48-52 (link)

    P2 Leftover development artifacts in specs array

    Four commented-out spec globs (basic-matchers.test.ts, soft-expect.test.ts, snapshot.test.ts, wdio-matchers.test.ts) were added alongside the existing wildcard. These look like temporary dev-time overrides used to run individual suites during development and should be removed before merging.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  5. playgrounds/jasmine/test/specs/expect-wdioImport/network-matchers.test.ts, line 513-521 (link)

    P2 Misaligned indentation on the last it block

    The final it('should support wdio expect asymmetric matchers') is indented with 8 spaces instead of 4, unlike every other it in the file. JavaScript ignores indentation so the test still runs correctly, but the inconsistency makes the code harder to read.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "Fix typing with `toBeResolvedTo` & `toBe..." | Re-trigger Greptile

Comment on lines 31 to 33
// Check if the line matches any exclusion pattern
const shouldExclude = excludeList.some(excludePath =>
line.trim().startsWith(excludePath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silencing Expected<T> type error hides a genuine resolution gap

Expected<T> is a @types/jasmine utility type used in jasmine-wdio-expect-async.d.ts to type toBeResolvedTo. Because @types/jasmine is excluded from tsconfig.types.json, the type is unresolved and the error is suppressed here. Consumers who add expect-webdriverio/jasmine-wdio-expect-async to their types without @types/jasmine will see the same TS2304 in their own project. Substituting the concrete type directly would keep the type check clean without a filter entry.

@dprevost-LMI dprevost-LMI marked this pull request as draft June 9, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jasmine Augmentations Limitations & Future Jasmine withContext broken

2 participants