close
Skip to content

Commit 6c3e4bd

Browse files
authored
fix(expect)!: fix toThrow("") behavior by reverting #6710 (#9643)
1 parent b639852 commit 6c3e4bd

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎packages/expect/src/jest-expect.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
748748
|| typeof expected === 'undefined'
749749
|| expected instanceof RegExp
750750
) {
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)
753752
}
754753

755754
const obj = this._obj

‎test/core/test/jest-expect.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ describe('jest-expect', () => {
115115
}).toThrow('')
116116
expect(() => {
117117
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
119122
expect([1, 2, 3]).toHaveLength(3)
120123
expect('abc').toHaveLength(3)
121124
expect('').not.toHaveLength(5)

0 commit comments

Comments
 (0)