Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using expect.any(String) in object comparison in jest

I have a code like below

    expect(insertedData).toEqual({
                id: expect.any(String),
                clientId: 'client1',
                ...

I expect id should match any string, but what I get as result is

enter image description here

Not sure what I missed.

Also I used like below still same error

expect(insertedData).toEqual(expect.objectContaining({
like image 771
Reza Avatar asked Aug 18 '26 07:08

Reza


1 Answers

It happens to me. Turns out the problem is not with the fields with expect.any() but the other field. Seems it just bad diff there.

like image 176
Yudi Supriyadi Avatar answered Aug 19 '26 22:08

Yudi Supriyadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!