Skip to content

Commit

Permalink
Fix deep equal comparison between promises
Browse files Browse the repository at this point in the history
  • Loading branch information
NoxWings committed Mar 5, 2021
1 parent ca676e4 commit f839c29
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 @@ -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);
});
});
});

0 comments on commit f839c29

Please sign in to comment.