You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there a way check if an object does not have a certain property? Basically, the opposite of expect.anything():
import{expect,test}from'vitest'test('object has "apples" key',()=>{expect({apples: 22}).toEqual({apples: expect.anything()})// expect apples to exist})test('object has not "apples" key',()=>{expect({bananas: 22}).toEqual({apples: expect.nothing()})// expect apples to NOT exist})
I know you could use expect({ bananas: 22 }).not.toHaveProperty('apples'), but this doesn't really work when combined with expect.arrayContaining() and expect.objectContaining().
I think an asymmetric matcher like expect.nothing() that does a simple !('key' in obj) check would be really helpful.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey,
is there a way check if an object does not have a certain property? Basically, the opposite of
expect.anything()
:I know you could use
expect({ bananas: 22 }).not.toHaveProperty('apples')
, but this doesn't really work when combined withexpect.arrayContaining()
andexpect.objectContaining()
.I think an asymmetric matcher like
expect.nothing()
that does a simple!('key' in obj)
check would be really helpful.Beta Was this translation helpful? Give feedback.
All reactions