Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch on setupBrowser argument #51

Open
hugueschabot opened this issue Dec 22, 2023 · 3 comments
Open

Type mismatch on setupBrowser argument #51

hugueschabot opened this issue Dec 22, 2023 · 3 comments

Comments

@hugueschabot
Copy link

hugueschabot commented Dec 22, 2023

If I create a new wdio (currently version 8.27) project with TypeScript and Testing Library, when I used setupBrowser I get a compilation error. However, the test can be executed normally so this is not a valid type error.

Example

import { expect, browser, $ } from "@wdio/globals";
import { setupBrowser } from "@testing-library/webdriverio";

describe("My Login application", () => {
  it("should login with valid credentials", async () => {
    const { getByRole } = setupBrowser(browser);
    // ...
  });
});

Compilation error:

Argument of type 'Browser' is not assignable to parameter of type 'BrowserBase'.
  Type 'Browser' is not assignable to type 'SelectorsBase'.
    The types returned by '$$(...)' are incompatible between these types.
      Type 'ChainablePromiseArray<ElementArray>' is not assignable to type 'Element[] | ChainablePromiseArrayBase<Promise<Element>> | Promise<Element[]>'.
        Type 'ChainablePromiseArray<ElementArray>' is missing the following properties from type 'Element[]': pop, push, concat, join, and 20 more.ts(2345)

Workaround

The workaround I found is to convince TypeScript that everything is okay by forcing a type cast: setupBrowser(browser as unknown as BrowserBase)

@jerrywithaz
Copy link

Any update on this? The latest webdriverio released breaking changes

@olivierwilkinson
Copy link
Collaborator

Heya,

Sorry for the slow response, I'm planning on looking into this soon!

Hopefully I'll have a solution this week, but it may take longer as supporting multiple versions of WebdriverIO can take some finessing with regards to the types.

@anuraghazra
Copy link

anuraghazra commented Apr 4, 2024

This is happening since wdio-testing-lib defines it's own wdio-types which seem to be outdated with v8 i think.

I did this workaround

// global.d.ts
import type { WebdriverIOQueries } from '@testing-library/webdriverio';
import type { BrowserBase } from 'webdriverio';

declare module '@testing-library/webdriverio' {
  function setupBrowser<Browser extends BrowserBase>(browser: Browser): WebdriverIOQueries;
}

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

No branches or pull requests

4 participants