Skip to content

Commit

Permalink
Fix deep equal comparison between promises (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoxWings committed May 24, 2021
1 parent ee77305 commit 144204d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Expand Up @@ -9,6 +9,7 @@ rules:

globals:
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 @@ -909,4 +909,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);
});
});
});

0 comments on commit 144204d

Please sign in to comment.