to have keys satisfying

Asserts that all keys of an object satisfy a given assertion or function.

Notice this assertion fails when given an empty object.

Aliases: to be a map whose keys satisfy, to be an object whose keys satisfy, to be a hash whose keys satisfy.

expect({ foo: 0, bar: 1, baz: 2, qux: 3 },
       'to have keys satisfying', function (key, value) {
    expect(key, 'to match', /^[a-z]{3}$/);
});
 
expect({ foo: 0, bar: 1, baz: 2, qux: 3 },
       'to have keys satisfying',
       'to match', /^[a-z]{3}$/);

In case of a failing expectation you get the following output:

expect({ foo: 0, bar: 1, baz: 2, qux: 3, quux: 4 },
       'to have keys satisfying',
       'to match', /^[a-z]{3}$/);
expected { foo0bar1baz2qux3quux4 }
to have keys satisfying 'to match'/^[a-z]{3}$/
 
{
  
foo0,
  
bar1,
  
baz2,
  
qux3,
  
quux
4
 
//
 
expected 'quux' to match /^[a-z]{3}$/
}