partial function

Matcher partial (Map map)

A matcher that partially matches a Map.

This matcher only matches the keys from map. If the compared map has additional keys, those keys are not evaluated and will always succeed in matching.

Example:

    var map = {"id": 1, "name": "foo"};
    // Validates that the key 'id' is an integer, but ignores key 'name'.
    // The following succeeds:
    expect(map, partial({"id": isInteger}));

You may enforce that the compared value does not have keys with isNotPresent.

Example:

  var map = {"id": 1, "name": "foo"};
  // Validates that the key 'id' is an integer and expects 'name' does not exist
  // The following will fail because name exists
  expect(map, partial({"id": isInteger, "name": isNotPresent}));

Implementation

Matcher partial(Map map) => new PartialMapMatcher(map);