[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(expect)!: fix `toThrow("")` behavior by reverting #6710 (#9643)

authored by

Hiroshi Ogawa and committed by
GitHub
(Apr 21, 2026, 1:17 PM +0200) 6c3e4bdb b639852c

+5 -3
+1 -2
packages/expect/src/jest-expect.ts
··· 748 748 || typeof expected === 'undefined' 749 749 || expected instanceof RegExp 750 750 ) { 751 - // Fixes the issue related to `chai` <https://github.com/vitest-dev/vitest/issues/6618> 752 - return this.throws(expected === '' ? /^$/ : expected) 751 + return this.throws(expected) 753 752 } 754 753 755 754 const obj = this._obj
+4 -1
test/core/test/jest-expect.test.ts
··· 115 115 }).toThrow('') 116 116 expect(() => { 117 117 throw new Error('error') 118 - }).not.toThrow('') 118 + }).toThrow('') // empty string is a substring of any error message 119 + expect(() => { 120 + throw new Error('error') 121 + }).not.toThrow(/^$/) // use regex to explicitly test non-empty error message 119 122 expect([1, 2, 3]).toHaveLength(3) 120 123 expect('abc').toHaveLength(3) 121 124 expect('').not.toHaveLength(5)