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: support .toHaveProperty('') #12251

merged 4 commits into from Jan 28, 2022


Copy link


When I try using .toHaveProperty() with an empty string:

expect({ '': 1 }).toHaveProperty('', 1);

It gets the following error:

    expect(received).toHaveProperty(path, value)

    Expected path: ""

    Expected value: 1
    Received value: {"": 1}

I believe it's a bug.

Test plan

Added a failed test.

Copy link
Contributor Author

chentsulin commented Jan 17, 2022

This regression was introduced by v27.4.0. I can confirm it works in v27.3.0

@chentsulin chentsulin force-pushed the toHaveProperty-empty-string-key branch from 7c7012a to 9317925 Compare January 23, 2022 06:17
Copy link
Contributor Author

Added a quick fix for the regression. @SimenB

Copy link

codecov-commenter commented Jan 23, 2022

Codecov Report

Merging #12251 (78beae9) into main (5d483ce) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12251   +/-   ##
  Coverage   67.51%   67.51%           
  Files         328      328           
  Lines       17246    17249    +3     
  Branches     5071     5072    +1     
+ Hits        11643    11646    +3     
  Misses       5570     5570           
  Partials       33       33           
Impacted Files Coverage Δ
packages/expect/src/utils.ts 96.09% <100.00%> (+0.05%) ⬆️

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 5d483ce...78beae9. Read the comment docs.

@chentsulin chentsulin force-pushed the toHaveProperty-empty-string-key branch from 9317925 to 399e472 Compare January 23, 2022 07:56
Copy link

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks!

@SimenB SimenB changed the title chore: add a failed test for .toHaveProperty('') fix: support .toHaveProperty('') Jan 28, 2022
@SimenB SimenB merged commit d1bc333 into jestjs:main Jan 28, 2022
@chentsulin chentsulin deleted the toHaveProperty-empty-string-key branch February 6, 2022 08:46
Copy link

github-actions bot commented Mar 9, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

Successfully merging this pull request may close these issues.

None yet

4 participants