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

Fix deep equal comparison between promises #217

merged 1 commit into from May 24, 2021

Conversation

NoxWings
Copy link
Contributor

@NoxWings NoxWings commented Mar 5, 2021

Fix issue #216 by explicitly checking Promise instances

Background

I found that sinon spy calledWith does not properly check promises equality and always returns true.
Reported here

Solution

Simple fix, I've just added explicit Promise instance checking similar to how Error or RegExp are checked. I've also added a couple tests to verify it. I haven't added a test to check promises against other type of data as that was already working but I can add a explicit test for that case if you want.

How to verify

  1. Check out this branch
  2. npm t (or just check the ci)

@codecov
Copy link

codecov bot commented Mar 5, 2021

Codecov Report

Merging #217 (f839c29) into master (ca676e4) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #217   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines          512       514    +2     
=========================================
+ Hits           512       514    +2     
Flag Coverage Δ
unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/deep-equal.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca676e4...f839c29. Read the comment docs.

@mantoni
Copy link
Member

mantoni commented Mar 7, 2021

Thanks a lot! 👍

We're still supporting old browsers like IE 11, where the Promise object doesn't exist. To avoid a ReferenceError, an additional typeof check is needed before using Promise. The corresponding test cases should be skipped in environments that don't support promises.

Here is an example how we do this for symbols:

before(function () {
if (typeof Symbol === "function") {
symbol = Symbol("id");
} else {
this.skip();
}
});

@NoxWings
Copy link
Contributor Author

Hi again sorry for the delay!
should I add any checks on the code itself apart from the tests?

@mantoni
Copy link
Member

mantoni commented Mar 16, 2021

@NoxWings Yes, it needs a typeof Promise check in the code as well. Thank you 🙏

@fatso83
Copy link
Contributor

fatso83 commented Apr 20, 2021

ping :) sinonjs/sinon#2345

@fatso83
Copy link
Contributor

fatso83 commented May 24, 2021

Actually, from Sinon 10 on (released on March 22) we do not support IE 11, so I see no reason to have this blocking. Merging :)

@fatso83 fatso83 merged commit 144204d into sinonjs:master May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants