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

Viewed 2118

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({
1 Answers

The problem on your expression relies on the first expectation which is

toEqual()

the expectation should use toMatchObject like:

expect(insertedData).toMatchObject({...
Related