Using Jest, I am trying to check for keys in a JavaScript Map object and toHaveProperty
does not work. In Mocha/Chai you can assert.hasAllKeys(map, keys)
JavaScript Map: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
Is there a way to do this?
toHaveProperty
is meant for checking paths on a plain javascript object. There aren't any built in matchers (that i'm aware of) that specialize in Map objects, so i'd recommend doing something like this:
expect(myMapObject.has(key)).toEqual(true)
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