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

toHaveClass has incorrect types when { exact: true } is used #7380

Open
6 tasks done
amanmahajan7 opened this issue Jan 29, 2025 · 1 comment · May be fixed by #7383
Open
6 tasks done

toHaveClass has incorrect types when { exact: true } is used #7380

amanmahajan7 opened this issue Jan 29, 2025 · 1 comment · May be fixed by #7383
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@amanmahajan7
Copy link

Describe the bug

error TS2353: Object literal may only specify known properties, and 'exact' does not exist in type 'RegExp'.

45   await expect.element(row3).toHaveClass(`${rowClassname} rdg-row-even`, { exact: true }); 

You can check the error here

It looks like this bug was introduced in
#7328
https://github.com/vitest-dev/vitest/pull/7328/files#diff-826106637c6076dd6dea2b15696fd38086cf5c7a20bf619a42ae7a11f3115d22R263-R264

Reproduction

Checkout adazzle/react-data-grid#3697
run npm run typescript

I can create another example if this information is not enough

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 7.02 GB / 31.73 GB
  Binaries:
    Node: 23.6.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.112)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4 
    @vitest/browser: ^3.0.2 => 3.0.4 
    @vitest/coverage-v8: ^3.0.2 => 3.0.4 
    @vitest/eslint-plugin: ^1.1.25 => 1.1.25 
    vite: ^6.0.11 => 6.0.11 
    vitest: ^3.0.2 => 3.0.4

Used Package Manager

npm

Validations

@hi-ogawa hi-ogawa added feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) labels Jan 30, 2025
@hi-ogawa
Copy link
Contributor

The previous one matches with jest-dom https://github.com/testing-library/jest-dom/blob/918b6fbcde10d4409ee8f05c6e4eecbe96a72b7a/types/matchers.d.ts#L261-L262, so we can probably just revert that one for now.

While experimenting locally, I'm not sure if there's a way to make typescript happy with both though. Probably the OP #7328 had an issue with the first one.

      await expect.element(div).toHaveClass(/xxx/, /yyy/, /zzz/)
      await expect.element(div).toHaveClass("xxx", { exact: true })

@hi-ogawa hi-ogawa linked a pull request Jan 30, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants