In Jest I need to test an expected value which can be either null or an object
{
main: {
prop1: 'abc',
prop2: '123',
}
}
but if it is an object, then I don't really care what main contains, I don't care about prop1 or prop2. I only need to assert that the object contains a key named main.
Jest reference mentions objectContaining, but it would still require that I specify at least one of the props, thus making my code unnecessarily verbose.
Is there any swift way to achieve an assertion that could be named objectContainingKey, like:
expect(something).toEqual(expect.objectContainingKey('main'))
The docs have something more suitable and more readable than the accepted answer:
expect(obj.main).toBeDefined();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With