js-must
js-must copied to clipboard
Add possibility to use custom equality comparator in
I have recently been using the .have.properties()
assertion a lot and in all my use cases I needed a value based comparison (deep equals) instead of ===
I would suggest to add an optional parameter to the properties method that will take a custom comparison function. The default value could be an implementation that uses '==='.
This is how it would look in coffeescript (sorry, for being too lazy to translate into ES)
isEqual = (a,b) -> a is b
(props, equals= isEqual) ->
obj =@actual
ok = @actual isnt null
if ok then for key,value of props
ok = key of obj and equals obj[key], props[key]
if not ok then break
@assert(ok, "have properties", {expected: props, diffable: true})