bun icon indicating copy to clipboard operation
bun copied to clipboard

`expect.toThrow()` fails with `expect.any()`

Open MattBDev opened this issue 1 year ago • 0 comments

What version of Bun is running?

1.1.20+ae1948925

What platform is your computer?

Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

In Jest the following test passes:

describe('Test expect.toThrow(expect.any())', () => {
  it('should throw an error', () => {
    expect(() => {
      throw new Error('error')
    }).toThrow(expect.any(Error))
  })
})

However in Bun the test fails with the following error:

4 | describe('Test expect.toThrow(expect.any())', () => {
5 |   it('should throw an error', () => {
6 |     expect(() => {
7 |       throw new Error('error')
8 |     }).toThrow(expect.any(Error))
           ^
error: expect(received).toThrow(expected)

Expected constructor: ExpectAny
Received constructor: Error

Received message: "error"

What is the expected behavior?

The expected behavior is that expect.toThrow() should be using the return value of the function expect.any().

What do you see instead?

No response

Additional information

I've tested this multiple times and created a project without any libraries to test it in Jest and in Bun. The issue is specifically with the behavior of expect.toThrow(expect.any()).

MattBDev avatar Jul 18 '24 22:07 MattBDev