Skip to content

Commit

Permalink
fix(expect): correct behavior of toThrowError with empty string par…
Browse files Browse the repository at this point in the history
…ameter (#6710)
  • Loading branch information
shulaoda authored Oct 15, 2024
1 parent 988e488 commit a61293e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
|| typeof expected === 'undefined'
|| expected instanceof RegExp
) {
return this.throws(expected)
// Fixes the issue related to `chai` <https://github.com/vitest-dev/vitest/issues/6618>
return this.throws(expected === '' ? /^$/ : expected)
}

const obj = this._obj
Expand Down
7 changes: 7 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ describe('jest-expect', () => {
// eslint-disable-next-line no-throw-literal
throw ''
}).toThrow(/^$/)
expect(() => {
// eslint-disable-next-line no-throw-literal
throw ''
}).toThrow('')
expect(() => {
throw new Error('error')
}).not.toThrowError('')
expect([1, 2, 3]).toHaveLength(3)
expect('abc').toHaveLength(3)
expect('').not.toHaveLength(5)
Expand Down

0 comments on commit a61293e

Please sign in to comment.