bun icon indicating copy to clipboard operation
bun copied to clipboard

`toHaveProperty` should always throw

Open paperclover opened this issue 2 years ago • 3 comments

What version of Bun is running?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

This is an inaccuracy in comparison to jest and vitest.

Both these lines should throw, bun doesnt throw on the .not because it inverts the test condition.

expect(null).not.toHaveProperty("length");
expect(null).toHaveProperty("length");

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

paperclover avatar Jun 17 '23 21:06 paperclover

I think it should always throw when the expect value is not an object.

Electroid avatar Jun 17 '23 21:06 Electroid

I think it should always throw when the expect value is not an object.

expect('string').toHaveProperty('length') should be true though.

Jest throws when the passed arg is null or undefined. See code here.

romellem avatar Jun 20 '23 14:06 romellem

null is indeed an object so I'm leaning towards this is indeed expected behavior. will followup after I can test in other libraries

nektro avatar May 24 '24 04:05 nektro