to satisfy

  • <Set> to [exhaustively] satisfy <Set>

Asserts that a Set instance has at least one element satisfying each given spec.

expect(
  new Set([1, 2, 3]),
  'to satisfy',
  new Set([
    1,
    expect.it('to be less than or equal to', 1),
    expect.it('to be greater than', 10),
  ])
);
expected Set([ 123 ]) to satisfy
Set([
  
1,
  
expect.it('to be less than or equal to'1),
  
expect.it('to be greater than'10)
])
 
Set([
  
1,
  
2
//
 
should be removed
  
3 
//
 
should be removed
  
//
 
missing: 
should be greater than 10
])

The exact number of elements in a Set must always be matched. However, nested objects are, be default, compared using "satisfy" semantics which allow missing properties. In order to enforce that all properties are present, the exhaustively flag can be used:

expect(
  new Set([1, { foo: true, bar: false }]),
  'to exhaustively satisfy',
  new Set([1, { foo: true }])
);
expected Set([ 1, { footruebarfalse } ])
to exhaustively satisfy Set([ 1, { footrue } ])
 
Set([
  
1,
  
footruebarfalse } 
//
 
should be removed
  
//
 
missing { footrue }
])