Skip to content
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

Fix deep equal comparison between promises #217

Merged
merged 1 commit into from May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Expand Up @@ -12,6 +12,7 @@ globals:
Set: false
Symbol: false
BigInt: false
Promise: false
Int8Array: false
Uint8Array: false
Uint8ClampedArray: false
Expand Down
4 changes: 4 additions & 0 deletions lib/deep-equal.js
Expand Up @@ -117,6 +117,10 @@ function deepEqualCyclic(actual, expectation, match) {
}
}

if (actualObj instanceof Promise && expectationObj instanceof Promise) {
return actualObj === expectationObj;
}

if (actualObj instanceof Error && expectationObj instanceof Error) {
return actualObj === expectationObj;
}
Expand Down
15 changes: 15 additions & 0 deletions lib/deep-equal.test.js
Expand Up @@ -903,4 +903,19 @@ describe("deepEqual", function () {
});
});
});

describe("promises", function () {
it("returns true if the same promise instance is compared", function () {
var promise = Promise.resolve();
var checkDeep = samsam.deepEqual(promise, promise);
assert.isTrue(checkDeep);
});

it("returns false if a different promise instance is compared", function () {
var promise1 = Promise.resolve();
var promise2 = Promise.resolve();
var checkDeep = samsam.deepEqual(promise1, promise2);
assert.isFalse(checkDeep);
});
});
});