to have keys satisfying

  • <object> to have keys satisfying <assertion>
  • <object> to have keys satisfying <any>

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',
  expect.it(function (key) {
    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}$/
 
[
  
'foo',
  
'bar',
  
'baz',
  
'qux',
  
'quux' 
//
 
should match /^[a-z]{3}$/
]