Skip to content

Commit

Permalink
Improve tests using Sets with deepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Jun 17, 2019
1 parent c861714 commit 4e4749f
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/deep-equal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,66 @@ describe("deepEqual", function() {
});
}

describe("when called with Set", function() {
before(function() {
if (typeof Set !== "function") {
this.skip();
}
});

it("should return `false` for different sized sets", function() {
var a = new Set();
var b = new Set();

a.add("a");

assert.isFalse(samsam.deepEqual(a, b));
});

it("should return `false` for different custom properties", function() {
var a = new Set();
var b = new Set();

a.add("a");
b.add("a");

a.prop = 42;

assert.isFalse(samsam.deepEqual(a, b));
});

it("should return `true` for equal sets", function() {
var VALUES = ["apple pie", "cherry pie", "key lime pie"];

var s1 = new Set();
var s2 = new Set();

VALUES.forEach(function(value) {
s1.add(value);
s2.add(value);
});

assert.isTrue(samsam.deepEqual(s1, s2));
});

it("should return `false` for un-equal sets", function() {
var VALUES = ["apple pie", "cherry pie", "key lime pie"];

var s1 = new Set();

VALUES.forEach(function(value) {
s1.add(value);
});

var s2 = new Set();
VALUES.slice(1).forEach(function(value) {
s2.add(value);
});

assert.isFalse(samsam.deepEqual(s1, s2));
});
});

/**
* Tests for cyclic objects.
*/
Expand Down

0 comments on commit 4e4749f

Please sign in to comment.