New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Evaluate symbolic keys for deep equality assertion #64
Changes from 8 commits
2b736a1
1bcabb7
95b37d4
7bd5f6e
67dc08b
c4188da
aac1b13
6605fa1
70d5f0b
cef5959
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ describe("deepEqual", function() { | |
var func = function() {}; | ||
var obj = {}; | ||
var arr = []; | ||
var symbol = Symbol("id"); | ||
var date = new Date(); | ||
var sameDate = new Date(date.getTime()); | ||
var sameDateWithProp = new Date(date.getTime()); | ||
|
@@ -364,6 +365,40 @@ describe("deepEqual", function() { | |
assert.isFalse(checkDeep); | ||
}); | ||
|
||
it("returns false if object has different symbolic properties", function() { | ||
var obj1 = {}; | ||
var obj2 = {}; | ||
obj1[symbol] = 42; | ||
obj2[symbol] = 43; | ||
var checkDeep = samsam.deepEqual(obj1, obj2); | ||
assert.isFalse(checkDeep); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MINOR: Can we make the tests a bit more concise? var obj1 = {[symbol]: 42};
var obj2 = {[symbol]: 43};
assert.isFalse(samsam.deepEqual(obj1, obj2)); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I tried that first, and the linter complained about an unexpected opening bracket. Changing it to this fixed the linting error. |
||
}); | ||
|
||
it("returns true if object has same symbolic properties", function() { | ||
var obj1 = {}; | ||
var obj2 = {}; | ||
obj1[symbol] = 42; | ||
obj2[symbol] = 42; | ||
var checkDeep = samsam.deepEqual(obj1, obj2); | ||
assert.isTrue(checkDeep); | ||
}); | ||
|
||
it("returns false if object missing expected symbolic properties", function() { | ||
var obj1 = {}; | ||
var obj2 = {}; | ||
obj2[symbol] = 42; | ||
var checkDeep = samsam.deepEqual(obj1, obj2); | ||
assert.isFalse(checkDeep); | ||
}); | ||
|
||
it("returns true if object contains additional symbolic properties", function() { | ||
var obj1 = {}; | ||
var obj2 = {}; | ||
obj1[symbol] = 42; | ||
var checkDeep = samsam.deepEqual(obj1, obj2); | ||
assert.isTrue(checkDeep); | ||
}); | ||
|
||
it("returns false if object to null", function() { | ||
var checkDeep = samsam.deepEqual({}, null); | ||
assert.isFalse(checkDeep); | ||
|
@@ -414,12 +449,12 @@ describe("deepEqual", function() { | |
assert.isFalse(checkDeep); | ||
}); | ||
|
||
it("returns true if arguments to array", function() { | ||
it("returns false if arguments to array", function() { | ||
var gather = function() { | ||
return arguments; | ||
}; | ||
var checkDeep = samsam.deepEqual([1, 2, {}, []], gather(1, 2, {}, [])); | ||
assert.isTrue(checkDeep); | ||
assert.isFalse(checkDeep); | ||
}); | ||
|
||
it("returns true if array to arguments", function() { | ||
|
@@ -430,13 +465,13 @@ describe("deepEqual", function() { | |
assert.isTrue(checkDeep); | ||
}); | ||
|
||
it("returns true if arguments to array like object", function() { | ||
it("returns false if arguments to array like object", function() { | ||
var gather = function() { | ||
return arguments; | ||
}; | ||
var arrayLike = { length: 4, "0": 1, "1": 2, "2": {}, "3": [] }; | ||
var checkDeep = samsam.deepEqual(arrayLike, gather(1, 2, {}, [])); | ||
assert.isTrue(checkDeep); | ||
assert.isFalse(checkDeep); | ||
}); | ||
|
||
it("returns true for same error", function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that this line was supposed to read
? Object.getOwnPropertySymbols(expectationObj)
?I just tried updating my project from sinon 7.2.7 to sinon 7.3.0, a change that includes this PR, and I get a lot of errors like this :
They all go away when I change the line as I said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Actually, the line obove should also just refer to
getOwnPropertySymbols
because we're "caching" the function at the top of the file. I would guess that your environment does not actually have symbols support, but it gets shimmed after Sinon is loaded.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is very probable, yes. Changing the above line to refer to just
getOwnPropertySymbols
withoutObject.
also gets rid of my errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you care to send a pull request to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is: #66