Skip to content

fix: preserve this context in defineHelper#10127

Closed
lawsonjl wants to merge 1 commit into
vitest-dev:mainfrom
lawsonjl:fix-preserve-this-in-definehelper
Closed

fix: preserve this context in defineHelper#10127
lawsonjl wants to merge 1 commit into
vitest-dev:mainfrom
lawsonjl:fix-preserve-this-in-definehelper

Conversation

@lawsonjl

Copy link
Copy Markdown

Description

The vi.defineHelper function drops the this context, even though the type signature of defineHelper (<F>(fn: F) => F) suggests that the call signature is preserved exactly. This change simply calls the wrapped function with the same this that the wrapper receives.

I intended to add a test, but I wasn't able to understand the existing tests well enough to be sure I was doing it right. At the very least, no existing tests suddenly started failing.

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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

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:.

@netlify

netlify Bot commented Apr 12, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2dc57c7
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69dbdb81a3e7330008bc75a2
😎 Deploy Preview https://deploy-preview-10127--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 project configuration.

@hi-ogawa

Copy link
Copy Markdown
Collaborator

Good catch. Not sure about the use case, but makes sense to fix.
For this one, we can add one more const myHelperWithThis = vi.defineHelper(function (this) { ... }) in test/cli/fixtures/assertion-helper/basic.test.ts and do some assertion one passing and one failing. You update snapshot by pnpm -C test/cli test assertion-helper.test.ts -u.

@hi-ogawa

Copy link
Copy Markdown
Collaborator

closing in favor of #10163

@hi-ogawa hi-ogawa closed this Apr 20, 2026
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.

2 participants