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

Changed toHaveStyle to use getPropertyValue instead of accessing the property directly #285

Merged
merged 10 commits into from Aug 11, 2020

Conversation

luanraithz
Copy link
Contributor

@luanraithz luanraithz commented Jul 29, 2020

What:

Fixes #280
Fixes #281

Why:

As #280, is a regression problem, which wasn't covered by tests.

How:

As mentioned by @just-boris, just changed to use the function getPropertyValue instead of accessing the property directly.

Checklist:

  • Documentation N/A
  • Tests
  • Updated Type Definitions N/A
  • Ready to be merged

<span data-testid="color-example" style="font-size: 12rem">Hello World</span>
`)
expect(queryByTestId('color-example')).toHaveStyle({
fontSize: 12
Copy link
Member

Choose a reason for hiding this comment

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

Why would this match 12rem? If I set font-size: 12; then this results in 12px. This seems a bit confusing to me.

Also: This test only works in JSDOM. In an actual browser the value would be resolved to (depending on the base font size) to 240px.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right! This test case doesn't make any sense as it is going to work only in JSDOM. Btw, I didn't know that, thanks! I'm going to change that.

It isn't clear to me if you are only against this test case or the idea of the api.

Copy link
Member

Choose a reason for hiding this comment

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

Just want to make sure that we're not documenting a test case that wouldn't work in a correct DOM environment.

Copy link
Member

Choose a reason for hiding this comment

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

Follow up on this. It seems from the discussion above that there's still something to be addressed here before this is ready. Right?

Copy link
Member

Choose a reason for hiding this comment

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

Is JSDOM actually returning 12rem here has the computed style? Then all we have to do is add a comment explaining that this test depends on the user agent (since it will return the computed font-size in pixel which depends on the base font size for rem).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to px right after your first comment, do you think that is still worth to leave a note about that behavior?

Copy link
Member

@gnapse gnapse left a comment

Choose a reason for hiding this comment

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

@luanraithz thanks a lot for this.

I left a few comments that may need your attention. But overall it looks good.

src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
<span data-testid="color-example" style="font-size: 12rem">Hello World</span>
`)
expect(queryByTestId('color-example')).toHaveStyle({
fontSize: 12
Copy link
Member

Choose a reason for hiding this comment

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

Follow up on this. It seems from the discussion above that there's still something to be addressed here before this is ready. Right?

src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
luanraithz and others added 5 commits July 31, 2020 10:18
Co-authored-by: Ernesto García <gnapse@gmail.com>
Co-authored-by: Ernesto García <gnapse@gmail.com>
Co-authored-by: Ernesto García <gnapse@gmail.com>
Co-authored-by: Ernesto García <gnapse@gmail.com>
Co-authored-by: Ernesto García <gnapse@gmail.com>
Copy link
Member

@gnapse gnapse left a comment

Choose a reason for hiding this comment

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

The CI build is failing due to some new code not following our eslint rules.

image

src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
src/__tests__/to-have-style.js Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #285 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #285   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines          315       315           
  Branches        72        72           
=========================================
  Hits           315       315           
Impacted Files Coverage Δ
src/to-have-style.js 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 9b0510b...e2b48ac. Read the comment docs.

@gnapse
Copy link
Member

gnapse commented Aug 11, 2020

@luanraithz I think this is almost ready to merge, but I wanted your input on two things before we do:

  1. Do you think this is a patch release? It is what I'm inclined it to be, but wanted your opinion.
  2. Why do you say this maybe fixes toHaveStyle doesn't take account of CSS custom properties #280? There's a new test being added here that pretty much resembles the example code in that issue, and the new test seems to make sure that that code now behaves as expected. Right?

@luanraithz
Copy link
Contributor Author

  1. Yeap, a patch seems to be the right choice.
  2. My main goal was to solve the toHaveStyle() doesn't behave as expected #281, but as the solution seemed to be the same I wrote "maybe". I will change the description, given that there is a test case for that as well.

@gnapse gnapse merged commit 92176e1 into testing-library:master Aug 11, 2020
@gnapse
Copy link
Member

gnapse commented Aug 11, 2020

🎉 This PR is included in version 5.11.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

toHaveStyle doesn't take account of CSS custom properties toHaveStyle() doesn't behave as expected
3 participants