8000 Add possibility to use custom equality comparator in · Issue #61 · moll/js-must · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Add possibility to use custom equality comparator in #61
Open
@bennidi

Description

@bennidi

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})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0