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(toHaveStyle): strictly match empty values #276

Merged
merged 1 commit into from Jul 15, 2020

Conversation

just-boris
Copy link
Contributor

What:

fixes the issue #272

Why:

Current implementation allows false positive matches. More examples in the linked issue

Checklist:

  • n/a Documentation
  • Tests
  • n/a Updated Type Definitions
  • Ready to be merged

@codecov
Copy link

codecov bot commented Jul 14, 2020

Codecov Report

Merging #276 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #276   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines          320       315    -5     
  Branches        71        72    +1     
=========================================
- Hits           320       315    -5     
Impacted Files Coverage Δ
src/utils.js 100.00% <ø> (ø)
src/to-have-style.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 33c35c6...c05ca3a. Read the comment docs.

Comment on lines -195 to -199
function parseJStoCSS(document, css) {
const sandboxElement = document.createElement('div')
Object.assign(sandboxElement.style, css)
return sandboxElement.style.cssText
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is currently not used anywhere else, so I decided to drop this completely

@@ -37,7 +38,7 @@ function printoutStyles(styles) {
// received computed styles
function expectedDiff(expected, computedStyles) {
const received = Array.from(computedStyles)
.filter(prop => expected[prop])
.filter(prop => expected[prop] !== undefined)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed to get a proper diff for expect(something).toHaveStyle({width: ''}) (expect width to be empty). Without this change it prints "the diff has no visual difference"

@@ -21,7 +21,8 @@ function isSubset(styles, computedStyle) {
!!Object.keys(styles).length &&
Object.entries(styles).every(
([prop, value]) =>
computedStyle.getPropertyValue(prop.toLowerCase()) === value,
computedStyle[prop] === value ||
computedStyle[prop.toLowerCase()] === value,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

computedStyle.getPropertyValue supports only dash-cased notation. Property getters work for both dash and camelCase

@gnapse gnapse merged commit 5bea350 into testing-library:master Jul 15, 2020
@testing-library testing-library deleted a comment from allcontributors bot Jul 15, 2020
@testing-library testing-library deleted a comment from allcontributors bot Jul 15, 2020
@gnapse
Copy link
Member

gnapse commented Jul 15, 2020

🎉 This PR is included in version 5.11.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@testing-library testing-library deleted a comment from allcontributors bot Jul 15, 2020
@gnapse
Copy link
Member

gnapse commented Jul 15, 2020

@all-contributors please add @just-boris for bug, code, test

@allcontributors
Copy link
Contributor

@gnapse

I've put up a pull request to add @just-boris! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants