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
calledWith ignores symbols used as property keys #1974
Comments
Thank you for putting this detailed analysis and code changes together. We're definitely lacking proper Symbol support in Sinon and should do something about it. Regarding your suggested solution, I think the fix should be slightly different: I'd say we should check the expectation for any symbol properties and only compare those to the actual. This means that additional symbol properties being added to the actual object do not break existing assertions. If we want to enforce strict matching of all symbols, then this would be a breaking change, because Sinon never looked at symbol properties before. Any opinions or other ideas @sinonjs/sinon-core? |
I like your suggestion. I'll put that solution together and open a PR for both samsam and formatio. |
That's some very detailed analysis, thank you ❤️ I like the proposed solution that doesn't break existing assertions 👍 |
@mantoni @mroderick samsam and formatio pull requests for your consideration. Although I implemented the proposed solution and all existing unit tests pass, I still have concerns about the backwards compatibility of the samsam change, which I detail in the solution section. |
Resolved by sinonjs/samsam#64 |
Describe the bug
Asserting
calledWith
ignores mismatched properties if they keys are JavaScript symbols.To Reproduce
Steps to reproduce the behavior:
Expected behavior
The above script should throw an
AssertError
because the mock was called with an object containing atrue
value when we were expecting afalse
value. It should behave similarly to this example that uses non-symbolic keys:Context (please complete the following information):
Additional context
I started working on a solution, but I wanted to raise an issue before opening pull requests like the contributing guide suggests to make sure I'm going down the right path. Using this change for samsam and this change for formatio, I get the behavior I expected for the script in the To Reproduce section:
Because symbols are unique, this:
will throw an
AssertError
(thanks @pettyalex for pointing this out):This, however, will not throw an
AssertError
:Unfortunately, the samsam change breaks one unit test:
This is because
arguments
has a property symbol callediterator
:The text was updated successfully, but these errors were encountered: