-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
p2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)pr welcome
Description
Describe the bug
toThrowError() treats an empty string (toThrowError('')) as it would if the value was undefined when it should reject an empty string as it is not equal to the error.
Reproduction
import { expect, test } from 'vitest'
function getFruitStock(type: string): void {
if (type === 'pineapples') {
throw new Error('Pineapples are not in stock')
}
}
test('throws on pineapples', () => {
// undefined error passes
expect(() => getFruitStock('pineapples')).toThrowError()
// error of empty string should fail as it does not represent the error but passes
expect(() => getFruitStock('pineapples')).toThrowError('')
})
System Info
System:
OS: Windows 10 10.0.19045
CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
Memory: 4.36 GB / 15.73 GB
Binaries:
Node: 22.4.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.19041.4355
npmPackages:
vitest: ^2.0.5 => 2.1.1Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
p2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)pr welcome