vitest-dev / vitest-dev/vitest

Expected behavior: `expect(() => { throw undefined }).toThrow('Input validation failed')` should fail.

Open
#7,260 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3-minor-bug upstream
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

Encountered unexpected behavior where throwing undefined still passed the tests. This occurred because I created a mock function meant to check the error before throwing, but I forgot to implement the check.

Expected behavior: expect(() => { throw undefined }).toThrow('Input validation failed') should fail.

Reproduction

Expected behavior: expect(() => { throw undefined }).toThrow('Input validation failed') should fail.

System Info
System:
    OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
    Memory: 2.06 GB / 7.57 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
    pnpm: 9.15.2 - ~/.nvm/versions/node/v22.12.0/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.264
  npmPackages:
    @vitest/coverage-v8: ^2.1.1 => 2.1.8 
    vitest: ^2.1.8 => 2.1.8
Used Package Manager

pnpm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided toThrow expectation with the repository's test runner, then locate the implementation and existing tests for toThrow. Add a regression test covering throw undefined with a non-empty expected message, and consider the issue complete when that expectation fails as described while existing matcher tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.