to satisfy

  • <any> to [exhaustively] satisfy [assertion] <expect.it>
  • <any> to [exhaustively] satisfy <function>
  • <any> to [exhaustively] satisfy <any>

Asserts that a value matches a given specification.

All properties and nested objects mentioned in the right-hand side object are required to be present. Primitive values are compared with to equal semantics:

expect({ hey: { there: true } }, 'to satisfy', { hey: {} });

To disallow additional properties in the subject, use to exhaustively satisfy:

expect({ hey: { there: true } }, 'to exhaustively satisfy', { hey: { there: true } });

Regular expressions and functions in the right-hand side object will be run against the corresponding values in the subject:

expect({ bar: 'quux', baz: true }, 'to satisfy', { bar: /QU*X/i });

Can be combined with expect.it or functions to create complex specifications that delegate to existing assertions:

expect({foo: 123, bar: 'bar', baz: 'bogus', qux: 42, quux: 'wat'}, 'to satisfy', {
    foo: expect.it('to be a number').and('to be greater than', 10),
    baz: expect.it('not to match', /^boh/),
    qux: expect.it('to be a string')
                  .and('not to be empty')
               .or('to be a number')
                  .and('to be positive'),
    quux: function (value) {
      expect(value, 'to be a string');
    }
});

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

expect({foo: 9, bar: 'bar', baz: 'bogus', qux: 42, quux: 'wat'}, 'to satisfy', {
    foo: expect.it('to be a number').and('to be greater than', 10),
    baz: expect.it('not to match', /^bog/),
    qux: expect.it('to be a string')
                  .and('not to be empty')
               .or('to be a number')
                  .and('to be positive'),
    quux: function (value) {
      expect(value, 'to be a number');
    }
});
expected { foo9bar'bar'baz'bogus'qux42quux'wat' } to satisfy
{
  
foo
expect.it('to be a number')
        .and('to be greater than'10),
baz
expect.it('not to match'/^bog/),
qux
expect.it('to be a string')
        .and('not to be empty')
      .or('to be a number')
        .and('to be positive'),
quuxfunction (value) {
  expect(value, 'to be a number');
}
}
 
{
  
foo
9
//
//
 
✓ 
should be a number
 and
⨯ 
should be greater than 10
  
bar'bar',
  
baz
'bogus'
//
//
//
 
should not match /^bog/
 
bogus
  
qux42,
  
quux
'wat' 
//
 
should be a number
}