Skip to content

fix(expect): handle nullish toHaveProperty values (fix #10735) - #10811

Merged
sheremet-va merged 1 commit into
vitest-dev:mainfrom
liyimil:agent/fix-nullish-to-have-property
Aug 11, 2026
Merged

sheremet-va merged 1 commit into
vitest-dev:mainfrom
liyimil:agent/fix-nullish-to-have-property

Conversation

@liyimil

@liyimil liyimil commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

toHaveProperty called Object.hasOwn before validating its received value, so null and undefined leaked the runtime error Cannot convert undefined or null to object.

This validates nullish inputs first and reports a matcher-specific TypeError for both regular and negated assertions. The regression test covers null and undefined in all four cases.

Resolves #10735

Codex was used as a personal assistant for this contribution. The issue, implementation, diff, and local validation were reviewed before submission.

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.
  • CI=true pnpm -C test/unit test --run test/jest-expect.test.ts (342 passed, 27 expected failures across threads, vmThreads, and forks)
  • pnpm typecheck
  • pnpm build
  • pnpm lint:fix

Documentation

  • No new functionality or documentation change is required.

Changesets

  • The PR title uses the repository's changelog convention.

@github-actions github-actions Bot added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Jul 22, 2026
@github-actions

Copy link
Copy Markdown

Hello @liyimil. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Confirm you've read, reviewed and stand behind its content
  • Confirm you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

@netlify

netlify Bot commented Jul 22, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3136d93
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a602441e2bc35000991aad9
😎 Deploy Preview https://deploy-preview-10811--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@liyimil

liyimil commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

我读了Issue、相关评论和贡献规范,做出了这次修改,是我本人提的

@liyimil

liyimil commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

我是真人,愿意为代码负责,使用了正确的模板,有一些代码是用codex辅助的

@github-actions github-actions Bot closed this Jul 26, 2026
@liyimil
liyimil deleted the agent/fix-nullish-to-have-property branch July 28, 2026 11:42
@liyimil
liyimil restored the agent/fix-nullish-to-have-property branch July 28, 2026 11:42
@sheremet-va sheremet-va reopened this Aug 11, 2026
@sheremet-va sheremet-va removed the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Aug 11, 2026
@github-actions github-actions Bot added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Aug 11, 2026
@github-actions

Copy link
Copy Markdown

Hello @liyimil. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Confirm you've read, reviewed and stand behind its content
  • Confirm you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

@sheremet-va
sheremet-va marked this pull request as ready for review August 11, 2026 11:35
@sheremet-va
sheremet-va merged commit 99e596d into vitest-dev:main Aug 11, 2026
49 of 53 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expect(null | undefined).toHaveProperty() throws an internal TypeError instead of a clean matcher error

2 participants