Jest expect.any() not working as expected
expect.toEqual
checks for equality of state.active
in your case. To achieve what you want, you have to make multiple expect
statements:
expect(state.active.active).toEqual(true)
expect(state.active.data).toEqual(expect.any(Array))
expect(state.active.ID).toEqual(expect.any(String))
You can use toMatchObject
:
expect(state.active).toMatchObject({
active: true,
data: expect.any(Array),
ID: expect.any(String)
});
See more examples in official documentation: https://jestjs.io/docs/en/expect#tomatchobjectobject