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

fix(expect): Correct generic MatchersObject this type in expect.extend #7526

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

pengooseDev
Copy link
Contributor

Description

fixes #6967

This PR fixes a TypeScript error where generic functions passed to expect.extend receive an incorrect this type. The issue was caused by the missing & ThisType<T> in the MatchersObject type definition.
I try to add a regression test, but I couldn't find an appropriate test example, so I've attached an image below.

Current
Current image
Fixed
Fixed image

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Feb 19, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit dcc75f2
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67b684456ccba400084a340b
😎 Deploy Preview https://deploy-preview-7526--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pengooseDev pengooseDev force-pushed the fix-matcher-object-type branch from e403bf0 to 58a7547 Compare February 19, 2025 09:05
@hi-ogawa
Copy link
Contributor

I try to add a regression test, but I couldn't find an appropriate test example

Thanks for the fix! Can we just add the repro here?

it('expect.extend', async () => {
expect.extend({

@pengooseDev
Copy link
Contributor Author

@hi-ogawa
I just followed the team's convention with the new custom matcher test method toBeTestedMatcherContext.
If any additional changes are needed, please feel free to let me know.

@pengooseDev pengooseDev force-pushed the fix-matcher-object-type branch from fe3eddc to dcc75f2 Compare February 20, 2025 01:24
@hi-ogawa hi-ogawa merged commit d5765f7 into vitest-dev:main Feb 20, 2025
13 checks passed
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.

expect.extend: MatchersObject functions do not receive the correct this type when generic
2 participants