Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#15806·webdriverio

[ Feature]: v10 – @wdio/jasmine-framework: keep Jasmine sync matchers synchronous (hybrid expect)

Author: dprevost-LMICreated Sep 29, 2026Updated Sep 29, 2026
LabelsIdea 💡

Is your feature request related to a problem?

In @wdio/jasmine-framework, the global expect is Jasmine's expectAsync. The adapter also wraps every Jasmine sync matcher as an async matcher. Because of this, expect(1).toBe(1) returns a Promise, but the types say it returns void.

Code: packages/wdio-jasmine-framework/src/index.ts

  • setupExpect(): const expect = jasmineEnv.expectAsync and then _setGlobal('expect', expect, …).
  • #setupMatchers(): jasmine.addMatchers is replaced with (m) => jasmine.addAsyncMatchers(transform(m)), and Jasmine's built-in matchers are registered as async ({ ...wdioMatchers, ...syncMatchers }).
  • #transformMatchers(): compare: async (actual, expected, ...args) => fn(util).compare(actual, expected, ...args).

expect-webdriverio also documents this in jasmine-wdio-expect-async.d.ts: "expectAsync is forced into the expect global ambient, making all Jasmine sync-matchers asynchronous", with a TODO to move that typing into @wdio/jasmine-framework.

Verified on v10 (jasmine-core 6.3.0, expect-webdriverio 8.0.0-alpha.0). I ran real Jasmine through JasmineAdapter with the real expect-webdriverio:

Spec Plain Jasmine @wdio/jasmine-framework
expect(1).toBe(1) return value undefined Promise (TypeScript says void)
Called spy: await expect(spy).toHaveBeenCalled() pass fail: Error: <toHaveBeenCalled> : Does not take arguments, use toHaveBeenCalledWith
Uncalled spy: expect(spy).toHaveBeenCalled() (no await) fail pass, with an unhandledRejection for the same error
stopSpecOnExpectationFailure: true, a failed sync expect, then more code spec stops spec continues (the failure is a rejected promise, not a throw)
await expect(elem).toHaveSize({ width, height }) n/a Jasmine's toHaveSize runs: …with size 3 to have size [object Object]

Effects:

  1. Sync matchers are async. Types say void, so no-floating-promises and similar rules do not find a missing await. Code after a failed assertion continues to run.
  2. False pass. #transformMatchers always passes expected, even when it is undefined. toHaveBeenCalled, toHaveSpyInteractions and toHaveNoOtherSpyInteractions check arguments.length > 1, so they always throw. Without await, the throw becomes an unhandled rejection and the spec passes.
  3. Stop on first failure is not possible. The wrapper cannot throw synchronously.
  4. WDIO toHaveSize is hidden. Jasmine's sync toHaveSize is spread over the WDIO matcher of the same name. Jasmine and WDIO share no other matcher names.
  5. Jasmine deprecation warning. Replacing jasmine.addMatchers gives: "DEPRECATION: Monkey patching detected… will break in a future release."

Minimal reproduction (Jasmine framework, any config):

javascript
describe('sync matchers', () => {
    it('should fail but passes', () => {
        expect(jasmine.createSpy('s')).toHaveBeenCalled()
    })
    it('should pass but fails', async () => {
        const s = jasmine.createSpy('s'); s()
        await expect(s).toHaveBeenCalled()
    })
    it('returns a Promise although typed as void', () => {
        console.log(expect(1).toBe(1) instanceof Promise) // true
    })
})

Describe the solution you'd like.

For v10, use a hybrid global expect. It sends each matcher call to the correct Jasmine expectation:

  • Sync: Jasmine built-in matchers and user jasmine.addMatchers matchers use env.expect(actual). They return void, throw when stopSpecOnExpectationFailure is set, and use Jasmine's own negativeCompare and messages.
  • Async: WDIO matchers (Object.keys(wdioCustomMatchers)), Jasmine async matchers (toBeResolved, toBeRejected, toBeResolvedTo, toBeRejectedWith, toBeRejectedWithError, toBePending) and user jasmine.addAsyncMatchers matchers use env.expectAsync(actual). They return a Promise.
  • .not and .withContext() return the same hybrid. Asymmetric matchers (expect.any, expect.stringContaining, …) stay on the function, as they do now.
  • Colliding name (toHaveSize): use WDIO when actual is a WDIO element, element array or chainable promise. Otherwise, use Jasmine.

Changes in the adapter:

  • Register only the WDIO matchers with addAsyncMatchers. Remove the syncMatchers spread.
  • Remove the jasmine.addMatchers replacement and #transformMatchers. This also removes the monkey-patching deprecation warning.
  • Types: move the typing from expect-webdriverio/jasmine-wdio-expect-async into @wdio/jasmine-framework (as expect-webdriverio's TODO asks). Jasmine sync matchers return void, and WDIO and Jasmine async matchers return Promise<void>.

User impact: await expect(1).toBe(1) continues to work, because await undefined is valid. await expect(el).toBeDisplayed() does not change. Tests that use Jasmine's toHaveSize on a WDIO element change behaviour. That is the only breaking case, so this fits v10.

Proof of concept: a Proxy over env.expect and env.expectAsync, applied after setupExpect() and run through the real adapter. Results:

  • Sync matchers return undefined.
  • Failing sync matchers fail the spec without await.
  • toHaveBeenCalled passes and fails correctly.
  • .not and .withContext messages are correct.
  • toBeResolvedTo, toHaveTitle, and .not with asymmetric matchers work.
  • User addMatchers matchers stay sync.
  • With stopSpecOnExpectationFailure: true, the spec stops at the first failure.

Describe alternatives you've considered.

  • Only fix #transformMatchers (forward the exact arguments, await them, and use the native negativeCompare). This fixes effect 2 only. Matchers stay async, the types stay wrong, and stop on first failure stays impossible.
  • Global expect = Jasmine sync expect, WDIO matchers only on expectAsync. This is Jasmine's own model, but every await expect(el).toBeDisplayed() must change. The migration cost is too high.
  • Global expect = expect-webdriverio (Jest style), as in Mocha. Jasmine matchers (toBeTrue, spy matchers on jasmine.createSpy) would stop working.

Additional context

Related bug found during the analysis (it can have its own issue): v10 removed jasmineOpts.stopSpecOnExpectationFailure and tells users to use jasmineOpts.oneFailurePerSpec (adapter constructor and website/docs/v10Migration.md). jasmine-core 6.3.0 has no oneFailurePerSpec option. Configuration.update() only reads stopSpecOnExpectationFailure, so oneFailurePerSpec: true has no effect. The rename must go in the opposite direction.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Source: webdriverio/webdriverio

View original on GitHubView discussion on GitHub