to have a value satisfying

  • <object> [not] to have a value [exhaustively] satisfying <assertion>
  • <object> [not] to have a value [exhaustively] satisfying <any>

Asserts that an object contains at least one value that satisfies a given value, function (wrapped in expect.it) or other assertion.

Note that this assertion fails if passed an empty object as the subject.

expect(
  { foo: { a: 1 }, bar: { b: 2 }, baz: { c: 3 }, qux: { d: 4 } },
  'to have a value satisfying',
  { a: 1 }
);
 
expect(
  { foo: 0, bar: 1, baz: 2, qux: 3 },
  'to have a value satisfying',
  expect.it(function (value) {
    expect(value, 'to be a number');
  })
);
 
expect(
  { foo: 0, bar: 1, baz: 2, qux: 3 },
  'to have a value satisfying',
  'to be a number'
);

The expected value will be matched against the value with to satisfy semantics, so you can pass any of the values supported by to satisfy. To use strict to satisfy semantics, you can use the "exhaustively" flag:

expect({ foo: { a: 1, b: 2 } }, 'to have a value satisfying', { a: 1 });
expect({ foo: { a: 1, b: 2 } }, 'to have a value exhaustively satisfying', {
  a: 1,
});
expected { foo: { a1b2 } } to have a value exhaustively satisfying { a1 }

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

expect(
  { foo: [10, 11, 12], bar: [14, 15, 16], baz: [17, 18, 19] },
  'to have a value satisfying',
  'to have items satisfying',
  expect.it('to be a number').and('to be below', 8)
);
expected { foo: [ 101112 ], bar: [ 141516 ], baz: [ 171819 ] } to have a value satisfying
to have items satisfying expect.it('to be a number')
        .and('to be below'8)

This assertion can be negated using the not flag:

expect({ foo: { a: 1, b: 2 } }, 'not to have a value satisfying', { a: 1 });
expected { foo: { a1b2 } } not to have a value satisfying { a1 }
 
{
  
foo: { a1b2 } 
//
 
should be removed
}