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

Changed types for extending matchers #6761

Open
6 tasks done
dosolkowski-work opened this issue Oct 21, 2024 · 3 comments
Open
6 tasks done

Changed types for extending matchers #6761

dosolkowski-work opened this issue Oct 21, 2024 · 3 comments

Comments

@dosolkowski-work
Copy link

Describe the bug

Similar to #6660, it looks like the Assertion<T> type is being found in @vitest/expect now instead of vitest itself. This changed from v2.1.2 to v2.1.3. As a result, the Extending Matchers documentation on Vitest's own website no longer works; TypeScript will not find the custom matcher functions. If this change is desired, please update the documentation on the website to match.

Reproduction

The code in Extending Matchers no longer works as-is. Instead, it must be changed to the following:

import '@vitest/expect'

interface CustomMatchers<R = unknown> {
  toBeFoo: () => R
}

declare module '@vitest/expect' {
  interface Assertion<T = any> extends CustomMatchers<T> {}
  interface AsymmetricMatchersContaining extends CustomMatchers {}
}

In addition, depending on the package manager setup, it may be necessary to add a package reference to @vitest/expect.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13950HX
    Memory: 12.14 GB / 31.61 GB
  Binaries:
    Node: 20.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.2 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitest/coverage-istanbul: ^2.1.3 => 2.1.3
    @vitest/eslint-plugin: ^1.1.7 => 1.1.7
    @vitest/ui: ^2.1.3 => 2.1.3
    vite: ^5.4.9 => 5.4.9
    vitest: ^2.1.3 => 2.1.3

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

It's working for me https://github.com/hi-ogawa/reproductions/tree/main/vitest-6761-expect-extend Can you provide a reproduction?

Copy link

Hello @dosolkowski-work. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@dosolkowski-work
Copy link
Author

I was able to reproduce using a project created from the StackBlitz link: https://stackblitz.com/edit/vitest-dev-vitest-mskyqm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants