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

.toHaveStyle() to support transform styles #26

Merged
merged 4 commits into from
Sep 7, 2020
Merged

.toHaveStyle() to support transform styles #26

merged 4 commits into from
Sep 7, 2020

Conversation

philipbulley
Copy link
Contributor

What:

Adds ability for .toHaveStyle() to compare transform styles.

Why:

Previously, .toHaveStyle() would only operate on shallow style properties, but transforms are specified as an object[]. The transform values would then be compared using strict equality and as such would never pass.

Furthermore, the diffs would serialize the transform values as [object Object] making both sides appear to be equal.

Ultimately, the test would fail regardless but the diff would tell us that everything is fine.

image

How:

We're now properly handling any style properties with object[] values and correctly serializing the expected and received passed to jestDiff. In both cases using recursion to perform the deep checks.

Checklist:

  • Documentation added to the
    docs
  • Typescript definitions updated (N/A)
  • Tests
  • Ready to be merged

I noticed that up until now, there have been no snapshots assertions, but I've added two small snapshots of the jestDiff output due to the added complexity in their generation. I think it's important to capture this — hope you don't mind.

@codecov
Copy link

codecov bot commented Apr 29, 2020

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #26   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines           92        94    +2     
  Branches        24        26    +2     
=========================================
+ Hits            92        94    +2     
Impacted Files Coverage Δ
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 2649017...13742db. Read the comment docs.

@brunohkbx brunohkbx linked an issue Aug 10, 2020 that may be closed by this pull request
@brunohkbx
Copy link
Collaborator

Hi @philipbulley. Thank you for contributing.
Can you please rebase your PR?

philipbulley and others added 2 commits September 7, 2020 10:51
# Conflicts:
#	README.md
#	src/__tests__/to-have-style.js
Copy link
Collaborator

@brunohkbx brunohkbx left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you @philipbulley.

@brunohkbx brunohkbx merged commit e598542 into testing-library:master Sep 7, 2020
brunohkbx added a commit that referenced this pull request Sep 7, 2020
They are breaking in master for some unknown reason and we don't need them at all
since we can assert the right behavior.
brunohkbx added a commit that referenced this pull request Sep 7, 2020
@bcarroll22
Copy link
Collaborator

🎉 This PR is included in version 3.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

mateusbw pushed a commit to mateusbw/jest-native that referenced this pull request Sep 8, 2020
* feat(toHaveStyle): Add ability to assert on transform styles

* fix(docs): Change doc block lang to typescript to prevent prettier adding parens
mateusbw pushed a commit to mateusbw/jest-native that referenced this pull request Sep 8, 2020
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 working with nested objects/arrays
3 participants