I have an API, and I want to claim that the expected data is returned. I don't care if more data is returned.
Therefore, I want to compare two objects ( expected and actual ), where all expected attributes should be equal to actual , but actual can contain more attributes:
var expected = { foo: 1, bar: { x1: 42, a1: [ 1, 2, { x: 7 } ] } } var actual = { foo: 1, whatever: 55,
Some more examples:
partiallyEqual({x: 1}, {a:2, x:1}) // return true partiallyEqual({x: 1}, {a:2, x:2}) // return false (x is different)
Arrays can (optionally) undergo a partial equivalent if actual contains additional elements.
partiallyEqual([1, 3], [1, 2, 3]) // return true partiallyEqual([3, 1], [1, 2, 3]) // return false (different order)
source share