Add Set::isEqual method in specs

This allows us to use the .toEqual matcher to compare Set
objects.
This commit is contained in:
Max Brunsfeld 2015-05-29 17:18:48 -07:00
parent 224575fc46
commit b59bec5f9d

View File

@ -49,6 +49,25 @@ Object.defineProperty document, 'title',
get: -> documentTitle
set: (title) -> documentTitle = title
Set.prototype.jasmineToString = ->
result = "Set {"
first = true
@forEach (element) ->
result += ", " unless first
result += element.toString()
first = false
result + "}"
Set.prototype.isEqual = (other) ->
if other instanceof Set
return false if @size isnt other.size
values = @values()
until (next = values.next()).done
return false unless other.has(next.value)
true
else
false
jasmine.getEnv().addEqualityTester(_.isEqual) # Use underscore's definition of equality for toEqual assertions
if process.env.CI